What is the difference between pointer and reference?

Answer Posted / mritunjay rai

1)it is not necessary to intialize a pointer at the time of
declaration.like:int a=10; int *p=&a;
u can also do int a=10; int *p; p=&a;
but in the case of reference it is necessary to
intialize a ref.at the time of declaration.like: int
&a=10;bcoz ref.is the secondname(aliase)for an object.means
it always refere an object so it's necessary to initialize
it.
2)u can assign NULL to a pointer.like int *p=NULL; but u
can't assign NULL to a reference.like int
&P=NULL//incorrect.
3)u can create array to a pointer but u can't create
array to a ref.
4) u can use pointer to pointer.but u can't use ref.to ref.
5) pointer is a new variable that contain the address of
another variable.but ref. is a second name (aliase) of the
same variable.
6)to store pointer we require extra memory.but for
reference we don't require extra memory.

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is iunknown? Explain some of commonly used methods provided by iunknown.

609


What is visual c++ runtime?

589


How do I uninstall visual c++?

546


How can we use cmutex?

562


Do I need ms visual c++ on my computer?

620






What is a copy constructor? What is the need for it?

579


Is visual c++ still used?

560


Do I need the microsoft visual c++?

565


difference between assert and verify.

592


How do I uninstall vc++ 2015?

514


Difference between critical section, mutex and semaphore.

632


How do I uninstall and reinstall microsoft visual c++ runtime libraries?

569


How do I fix microsoft visual c++ 2015 setup failed?

583


What is vcredist_x86 exe?

610


What is mfc in vc++?

721