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

What is an incomplete type in c++?

762


Define upcasting.

590


Define a nested class.

611


Explain what are accessor methods?

665


Is c++ the most powerful language?

562






What is an object in c++?

610


Is swift faster than go?

613


which of the following is not an secondary constant a) array b) real c) union

1256


Describe delete operator?

619


What is difference between array and vector in c++?

557


Why do we need templates?

542


Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).

615


What is a literal in c++?

566


Why are pointers used?

578


What do the keywords volatile and mean mutable?

603