[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

pointers, references and variables in any language differences

I do not understand long articles about differences between variables, references, pointers



But those that do support references always require that the reference is always filled with value to some existing objects (i.e. some address). Pointers on the other hand can contain a special value named nil, NULL, nullptr or the like that says "pointing to nowhere".

so now I know one difference between pointer and reference

Are there any other differences without an long explanation that I do not understand yet.
0
rgb192
Asked:
rgb192
4 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
Probably not.  While those are generic computer science terms, for any specific language you will still need to know and understand the details of how they implemented it.
0
 
phoffricCommented:
>> references always require that the reference is always filled with value to some existing objects (i.e. some address

It may be filled initially, yet if the block holding the object being referenced is completed (e.g., a function returns), then the reference will be referring to a non-existing item. (This is similar to a non-null pointer problem, but I mention this because the above quote may be misinterpreted.)
0
 
HooKooDooKuCommented:
A reference and a pointer are pretty much the same thing under the hood.  When you pass an object by reference or by pointer, the compiler still passes a pointer.  It's just the compiler takes care of de-referencing the pointer for a reference variable, but you have to take that extra step when dealing with a pointer.

But the other difference is that a reference variable always has to be assigned to a valid object.  By contrast, a pointer can point to anything (bad memory location) or to nothing (NULL Pointer).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
phoffricCommented:
Please post a quote of something that you do not understand in those articles.
0
 
peprCommented:
There are always two sides: a machine and a man. Programming language is in between. The language has syntax (how it is written) and semantics (what does it mean). The processor uses the address of the memory space to get there. This is actually the meaning of both using the pointer variable and also of the reference variable. But it looks differently when written in a programming language.

In Python and in Java, you can use only references. There are no pointers. C++ is more rich in syntactic sense -- you can also use the more complex, more low-level, less restricting, bit also more difficult (more error-prone) pointer approach.

To understand the difference, you need to learn and compare the examples in the language that allows both. I suggest C++. Study:

1) working with a simple variable,
2) working with the variable through a reference variable,
3) working with the variable through a pointer variable.
0
 
rgb192Author Commented:
generic computer science terms
reference is always filled with value to some existing objects and pointer can point to null
The processor uses the address of the memory space to get there. This is actually the meaning of both using the pointer variable and also of the reference variable.

Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now