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


Please Help Members By Posting Answers For Below Questions

What is pair in c++?

623


Give example of a pure virtual function in c++?

581


How can a called function determine the number of arguments that have been passed to it?

655


Why c++ is called oop?

587


How many different levels of pointers are there?

652






What methods can be overridden in java?

665


What are libraries in c++?

601


What is type of 'this' pointer? Explain when it is get created?

582


What is a terminating character in c++?

756


What is the exit function in c++?

536


Why isn't sizeof for a struct equal to the sum of sizeof of each member?

532


What is a memory leak c++?

585


Differentiate between a copy constructor and an overloaded assignment operator.

635


How does a copy constructor differs from an overloaded assignment operator?

549


Explain the difference between realloc() and free() in c++?

528