What is the difference between Pointer and a Reference?
When you would use them?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / man
Reference is alias of a variable i.e. a constant pointer
which reference to a variable and can not be NULL.
You can not can get the address of ref. They are used as a
variable.
Pointers are variale that hold address of variable and can
be NULL. And can point to any number of variable.
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / vinay bondade
A Pointer is not a condt pointer unless you define it in
that way,but a referrence on the contrary is a const
pointer by default and adding to this implementation it is
deferrenced automatically.
| Is This Answer Correct ? | 1 Yes | 3 No |
Answer / nav
pointer are variable and no need to be initilise,but
refrence is the rename of variable and must be
initilise.pointer also assign null value but reference not
assign null value.
| Is This Answer Correct ? | 1 Yes | 3 No |
if there is binary tree which one is the easiest way to delete all child node?
What is the difference between global variables and static varables?
What ANSI C++ function clears the screen a) clrscr() b) clear() c) Its not defined by the ANSI C++ standard
What is a container class? What are the types of container classes?
What are the uses of typedef in a program?
What is exception handling in C++?
Is it legal in c++ to overload operator++ so that it decrements a value in your class?
Why cstdlib is used in c++?
What is difference between malloc()/free() and new/delete?
Differences between private, protected and public and give examples.
Can you explicitly call a destructor on a local variable?
Do class method definitions?