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 bubble sort c++?
What is the default access level?
What is abstraction in c++ with example?
What are the different types of comments allowed in c++?
Explain dangling pointer.
What is virtual methods?
What does h mean in maths?
Describe the advantage of an external iterator.
What are the various storage classes in C++?
What are arithmetic operators?
What is #include iomanip?
How one would use switch in a program?
What is a storage class? Mention the storage classes in c++.
What is implicit pointer in c++?
What does return 0 do in c++?