What is the difference between Pointer and a Reference?
When you would use them?

Answer Posted / srihariraju

A reference just renames a memory location for the
reader/programmer. Its more like renaming a constant with
#define. The reference does not really 'contain' the
address, instead the comiler *could* just substitute the
address for the reference at the assembly code level.

A pointer is a variable (it 'must' have a memory location
of its own (barring odd compiler tricks)) that *can* be
used like a reference or it can point to nothing (NULL) (a
reference cannot do that) and a pointer can get new memory
from the os (new command) while a reference must 'point' to
existing memory.

Is This Answer Correct ?    14 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the precedence when there is a global variable and a local variable in the program with the same name?

610


Which sort does c++ use?

567


what is scupper?

1880


What are the four partitions in which c++ compiler divides the ram?

686


What are the various storage classes in C++?

639






What is data hiding c++?

591


Can a built-in function be recursive?

572


What is linked list in c++?

678


What is guard code in c++?

619


What are static type checking?

616


What is exception handling? Does c++ support exception handling?

575


List the issue that the auto_ptr object handles?

595


How many different levels of pointers are there?

644


What problems might the following macro bring to the application?

605


If you want to share several functions or variables in several files maitaining the consistency how would you share it?

538