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
In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that
What is the use of register keyword with the variables?
What is the difference between equal to (==) and assignment operator (=)?
What is the best it certification?
What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random
Is string data type in c++?
What does ios :: app do in c++?
How does work in c++?
What are virtual constructors/destructors?
Write my own zero-argument manipulator that should work same as hex?
What is meant by the term name mangling in c++?
Write a program to show polymorphism in C++?
What are the extraction and insertion operators in c++?
Why is c++ still used?
What gives the current position of the put pointer?