C++ Programming - References - Discussion

Discussion :: References - General Questions (Q.No.14)

14. 

Which of the following statement is correct?

[A]. A reference is a constant pointer.
[B]. A reference is not a constant pointer.
[C]. An array of references is acceptable.
[D]. It is possible to create a reference to a reference.

Answer: Option A

Explanation:

No answer description available for this question.

Vishwanath said: (Oct 28, 2013)  
A constant pointer is the one whose pointing location is fixed and can't be modified.

e.g int num,sum;
int &b=sum;

here b is pointing to the variable num location and is fixed. We cannot make b to point to some other variable, Hence the name constant pointer.

int &b=sum; IS NOT ACCEPTED. Hence the name constant pointer.

Shantanu said: (Jun 27, 2015)  
We can create reference to a reference.

CODE SNIPPET:

--------------------------
int i = 10;
int &ref1 = i;
int &ref2 = ref1;
cout<<ref1<<" "<<ref2;
-----------------------------------

Here o/p will be 10 10.

Daniel Sandor said: (Nov 20, 2015)  
Dear @Shantanu!

In your example ref2 is not a reference to a reference, because at the moment ref2 is initialized, ref1 is automatically dereferenced. So it is a reference to an int.

Trupti said: (Dec 11, 2015)  
Some time it said reference is constant pointer sometime not. What is correct answer?

Kunal Budhiraja said: (Oct 29, 2017)  
A const pointer can be null whereas reference can not be null.

Jaideep said: (Jul 12, 2018)  
Reference and constant pointer are fundamentally very different while one has its own memory at which various values can be stored the other shares the same memory of the object it refers too and can never be null in nature.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.