C++ Programming - References - Discussion
Discussion Forum : References - General Questions (Q.No. 9)
9.
Which of the following statements is correct?
- An array of references is acceptable.
- We can also create a reference to a reference.
Discussion:
13 comments Page 1 of 2.
Sonu patel said:
1 decade ago
Can anyone how array of pointers and pointer to pointer is not possible?
Dimaag_chala said:
1 decade ago
Pointers are different then references. You can obviously have pointers to pointers but the question asks if We can also create a reference to a reference. THAT IS NOT POSSIBLE.
Also, 1st option is wrong for obvious reasons ;).
Also, 1st option is wrong for obvious reasons ;).
Ronagrawal@gmail.com said:
1 decade ago
int a = 12;
int &b = a;
int &c = b;
cout<<c;
b is a reference to a and c is a reference to b so is it is reference to a reference?
int &b = a;
int &c = b;
cout<<c;
b is a reference to a and c is a reference to b so is it is reference to a reference?
Sujit said:
1 decade ago
Reference to a reference cannot be created as reference is nick name given to that variable and reference doesn't have any memory like pointers which has 4 bytes of memory to store address of variables where it points.
Khushboo kumari said:
1 decade ago
Reference is nothing but an alias of a variable i.e. another name given to some variable, it behaves like a constant pointer but is not a pointer, as pointer stores address of the variable and point to its value using '*'. Similarly reference also points to the value of some variable but it act as its another name and as a constant pointer, once initialized cannot refer any other value.
Swapnil said:
8 years ago
Reference to another reference can be created.
Sagar said:
8 years ago
@ALL.
My explanation is;
int a =10;
int &r=a; // r is a reference of a
int &p=r;
cout<<"a = "<<a <<" &a = "<<&a<<endl;
cout<<"r = "<<r <<" &r = "<<&r<<endl;
cout<<"p = "<<r <<" &p = "<<&r<<endl;
And the output is =
a = 10 &a = 0x7fff53f201a4
r = 10 &r = 0x7fff53f201a4
p = 10 &p = 0x7fff53f201a4.
My explanation is;
int a =10;
int &r=a; // r is a reference of a
int &p=r;
cout<<"a = "<<a <<" &a = "<<&a<<endl;
cout<<"r = "<<r <<" &r = "<<&r<<endl;
cout<<"p = "<<r <<" &p = "<<&r<<endl;
And the output is =
a = 10 &a = 0x7fff53f201a4
r = 10 &r = 0x7fff53f201a4
p = 10 &p = 0x7fff53f201a4.
Debajyoti Dev said:
8 years ago
Wrong, reference to reference can be created.
int a = 7;
int &b = a;
int &c = b;
c = 10;
cout << a;
int a = 7;
int &b = a;
int &c = b;
c = 10;
cout << a;
(1)
Jaideep said:
7 years ago
You cannot create a reference to a reference, the examples stated in the discussion are all rvalue references.
Abhijeet said:
6 years ago
The reference to a reference i.e.
int &(&ref2)=ref;
So, not acceptable.
int &(&ref2)=ref;
So, not acceptable.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers