C++ Programming - References - Discussion
Discussion Forum : References - General Questions (Q.No. 14)
14.
Which of the following statement is correct?
Discussion:
6 comments Page 1 of 1.
Jaideep said:
7 years ago
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.
Kunal Budhiraja said:
8 years ago
A const pointer can be null whereas reference can not be null.
Trupti said:
10 years ago
Some time it said reference is constant pointer sometime not. What is correct answer?
Daniel Sandor said:
10 years ago
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.
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.
Shantanu said:
1 decade ago
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.
CODE SNIPPET:
--------------------------
int i = 10;
int &ref1 = i;
int &ref2 = ref1;
cout<<ref1<<" "<<ref2;
-----------------------------------
Here o/p will be 10 10.
(2)
Vishwanath said:
1 decade ago
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers