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


Please Help Members By Posting Answers For Below Questions

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

840


What is the use of register keyword with the variables?

745


What is the difference between equal to (==) and assignment operator (=)?

774


What is the best it certification?

821


What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random

881


Is string data type in c++?

789


What does ios :: app do in c++?

775


How does work in c++?

820


What are virtual constructors/destructors?

762


Write my own zero-argument manipulator that should work same as hex?

794


What is meant by the term name mangling in c++?

716


Write a program to show polymorphism in C++?

830


What are the extraction and insertion operators in c++?

760


Why is c++ still used?

795


What gives the current position of the put pointer?

754