What is the difference between a pointer and a reference?

Showing Answers 1 - 18 of 18 Answers

vit2007

  • Feb 26th, 2007
 

The reference is similar to a pointer, but should be initialized at the declaration and cannot be pointed to any other object in the future. There is also a syntactic difference in dereferencing (no need for a * in front of the reference).

  Was this answer useful?  Yes

satyarth

  • Mar 22nd, 2007
 

1-A reference can not exist by itself i.e. without something to refer to. 
 pointers are variables themselves, they point at somethin concrete or just  at nothing
2-Reference are aliased for other variables & can not be realised to other variables.
  while pointers can be reassigned to point to different variables.
3- when address-of operator & is used with a reference the expression yields the address of the variable to which the reference applied.
while pointers are variables themselves, so the address of a pointer shows the address of variable.

dasam

  • Mar 29th, 2007
 

1. references can be visualised as constant pointers.2. no need to dereference the references but a pointer to be dereferenced3. arthimetic operations cannot be performed on references whereas we can do with pointers4. reference to reference is not possible, we can take pointer to pointer.hope this info is helpful :)

Valentin

  • Jul 2nd, 2007
 

A better question is what is a reference?
I found the best definitions a reference in Dewhurst book "C++ Common Knowledge"

"A reference is another name for an object. Once a reference is initialized with an object, either the object name or the reference name may be used to refer to the object"

Therefore a reference is an alias to an object, not a pointer. Some C++ compilers implement references as pointers.

There are three major differences, between reference and pointers:

1. References cannot be null
2. References must be initialized
3. References must refer to an object

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions