GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 117 of 203    Print  
What is the difference between a pointer and a reference?

  
Total Answers and Comments: 5 Last Update: May 10, 2008     Asked by: Nayan 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: satyarth
 
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.

Above answer was rated as good by the following members:
Rahul_ars, j_l_larson
February 26, 2007 19:01:06   #1  
vit2007 Member Since: February 2007   Contribution: 1    

RE: What is the difference between a pointer and a ref...
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).
 
Is this answer useful? Yes | No
March 22, 2007 04:18:03   #2  
satyarth        

RE: What is the difference between a pointer and a ref...
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.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 29, 2007 09:22:26   #3  
dasam Member Since: March 2007   Contribution: 33    

RE: What is the difference between a pointer and a ref...
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 :)
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 02, 2007 23:45:21   #4  
Valentin        

RE: What is the difference between a pointer and a ref...

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


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 10, 2008 03:02:02   #5  
pammi_11 Member Since: April 2008   Contribution: 4    

RE: What is the difference between a pointer and a reference?
pointer holds the address of a variable.
reference holds the address of duplicate of that variable.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape