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 an incomplete type in c++?
Define upcasting.
Define a nested class.
Explain what are accessor methods?
Is c++ the most powerful language?
What is an object in c++?
Is swift faster than go?
which of the following is not an secondary constant a) array b) real c) union
Describe delete operator?
What is difference between array and vector in c++?
Why do we need templates?
Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).
What is a literal in c++?
Why are pointers used?
What do the keywords volatile and mean mutable?