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 the full name of logo?

596


What is the full form of c++?

622


Difference between pointer to constant and constant pointer to a constant. Give example.

652


What is the two main roles of operating system?

517


What is an adjust field format flag?

647






Why is main function important?

588


How we can differentiate between a pre and post increment operators during overloading?

600


an integer constant must have atleast one a) character b) digit c) decimal point

556


What is meant by the term name mangling in c++?

524


Explain how we implement exception handling in c++?

580


Give 10 points of differences between C & C++.

631


What are register variables?

650


Is map thread safe c++?

636


What is c++ prototype?

591


What is the use of 'using' declaration in c++?

634