Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What are the differences between a pointer variable and a reference variable in C++ Language?

But what are the difference between them?
Need more explanation!
by

2 Answers

sandhya6gczb
A pointer variable in C++ holds the memory address of a variable whereas a reference variable is an alias, that is an original variable with another name.
A pointer can be initialized with NULL values whereas a reference cannot have a NULL value.
A pointer has its own memory address whereas a reference has the same address as the original value.
Example*
// pointer
int x=5;
int
p;
p=&x;

//reference
int x=5;
int &r=x
Sonali7
A pointer variable in C++ is a variable that holds the memory address of another variable whereas the reference is an alias for an already existing variable.
Pointers dereferenced with a * whereas references can be used simply, by name.
A pointer can be changed to point to any variable of the same type whereas a reference if once initialized to a variable, it cannot be changed to refer to a variable object.
A pointer can be assigned to point to a NULL value whereas a reference cannot be NULL.

Login / Signup to Answer the Question.