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 difference between a definition and a declaration?
What are register variables?
Is empty stack c++?
What is prototype in c++ with example?
What is difference between c++ 11 and c++ 14?
Explain method of creating object in C++ ?
Explain the difference between abstract class and interface in c++?
Are there any special rules about inlining?
What are abstract data types in c++?
What is nested class in c++?
How can you create a virtual copy constructor?
What is stream and its types in c++?
Why c++ is so important?
What are shallow and deep copy?
what are the types of Member Functions?