What is the difference between pointer and reference?
Answers were Sorted based on User's Feedback
Answer / treker
1. Pointer can refer NULL, refernce cannot be NULL
2. Pointer can derefernce to another address, Reference
once initialized stays that way till it dies.
3. pointer may not associate with a legitimate memory but
References should associate with certain memory.
4. pointer may not be initialized while created but
refernce has to intialized when it is created.
Is This Answer Correct ? | 50 Yes | 4 No |
Answer / praveena
A reference must always refer to some object and,
therefore, must always be initialized;
pointers do not have such restrictions. A pointer can be
reassigned to point to different
objects while a reference always refers to an object with
which it was initialized.
Is This Answer Correct ? | 30 Yes | 5 No |
Answer / noopur sharma(m.c.a. r.u)
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 ? | 12 Yes | 2 No |
Answer / hari krishna
http://www.dgp.toronto.edu/~patrick/csc418/wi2004/notes/Poin
tersVsRef.pdf
Is This Answer Correct ? | 10 Yes | 2 No |
Answer / 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 |
Answer / basudha
A reference must always refer to some object and,
therefore, must always be initialized;
pointers do not have such restrictions. A pointer can be
reassigned to point to different
)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.
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / satyendra singh
i am also satisfied whose already given answer but major
differnce b/w reference and pointer
1--refrence and pointer both are refer memori address
2--with help of pointer arithmatic calculation done but
pointer not done;
3--refrence tracked by garwage collection but pointer not done;
4--referece must alway refer object which must initialized
Is This Answer Correct ? | 0 Yes | 3 No |
What is microsoft visual c++ runtime library error?
What is the difference between serialization and deserialization?
4 Answers Cap Gemini, HCL, MBT,
how to declare and populate an array of checkBoxes
Name some examples of the different types of windows found in a Windows application?
What are the two forms of the #include preprocessor directive?
What is a microsoft visual c++ 2008 redistributable?
What is cwinthread class? Explain its advantages.
What Is Your Greatest Weakness?
4 Answers Apple, Infosys, IOCL, Servion, TCS, VisionTek,
What is a mnemonic?
Do I need the microsoft visual c++?
hi i have 1180 in gre and 109 in toefl i have one more backlog to clear now. My classes got over in 2007 july. can i put a course completion certificate for my f1 visa interview. plz help
What are some differences between a form view and a dialog box?
2 Answers DS Group, Manipal Ecommerce,