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

How many types of modularization are there in c++?

566


What is the difference between a template and a macro?

585


Does c++ have finally?

571


What is the difference between function overloading and operator overloading?

579


what is Member Functions in Classes?

620






What is std :: flush?

578


Describe private, protected and public – the differences and give examples.

589


List the features of oops in c++?

578


Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.

1721


Is ca high or low level language?

586


What are the different types of comments allowed in c++?

581


What is meaning of in c++?

674


Explain rethrowing exceptions with an example?

610


What is the best free c++ compiler for windows?

592


What is the cout in c++?

554