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 difference between class and structure in c++?
how to access grid view row?
Does c++ cost money?
What is the output of the following program? Why?
What is the use of :: operator in c++?
What is private public protected in c++?
How many ways can a variable be initialized into in C++?
Can recursive program be written in C++?
What are register variables?
What is class in c++ with example?
What is data structure in c++?
Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.
What is a pointer how and when is it used?
What is a type library?
What is c++ virtual inheritance?