What is the difference between reference type and pointers.
Answer Posted / k govind
In addition to the previous answer given in Answer #1,
namely References must point to valid objects at the time
of declaration, references also has the following
limitation.
Once a reference is assigned, there's no way you can modify
the reference. However for a pointer type, variable
assignment is legal.
e.g.,
int i, j;
int *pi, *pj;
pi = &i; // pointer to i
pj = &j; // pointer to j
int &k = i; // reference to i
pi = pj; // pi no longer points to i, instead
// it is now pointing to j
k = j; // The reference k is still with i, it is only
// the value of i that is now modified. i is
// assigned the value of j
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What is pair in c++?
Give example of a pure virtual function in c++?
How can a called function determine the number of arguments that have been passed to it?
Why c++ is called oop?
How many different levels of pointers are there?
What methods can be overridden in java?
What are libraries in c++?
What is type of 'this' pointer? Explain when it is get created?
What is a terminating character in c++?
What is the exit function in c++?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
What is a memory leak c++?
Differentiate between a copy constructor and an overloaded assignment operator.
How does a copy constructor differs from an overloaded assignment operator?
Explain the difference between realloc() and free() in c++?