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

How does the copy constructor differ from the assignment operator (=)?

857


Eplain extern keyword?

774


Evaluate as true or false: !(1 &&0 || !1) a) True b) False c) Invalid statement

849


What is an operator in c++?

801


Do class declarations end with a semicolon? Do class method definitions?

863


Which is not an ANSII C++ function a) sin() b) tmpnam() c) kbhit()

1268


Write is a binary search tree? Write an algo and tell complexity?

798


What is operators in c++?

791


Is it possible to write a c++ template to check for a function's existence?

794


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

842


What are the c++ access specifiers?

1063


When do we use copy constructors?

788


What is atoi in c++?

812


Can you pass an array to a function in c++?

747


What is the difference between an array and a list?

775