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
What is the precedence when there is a global variable and a local variable in the program with the same name?
Which sort does c++ use?
what is scupper?
What are the four partitions in which c++ compiler divides the ram?
What are the various storage classes in C++?
What is data hiding c++?
Can a built-in function be recursive?
What is linked list in c++?
What is guard code in c++?
What are static type checking?
What is exception handling? Does c++ support exception handling?
List the issue that the auto_ptr object handles?
How many different levels of pointers are there?
What problems might the following macro bring to the application?
If you want to share several functions or variables in several files maitaining the consistency how would you share it?