C++ Programming - References - Discussion
Discussion Forum : References - General Questions (Q.No. 4)
4.
Which of the following statements is correct?
- Change a reference changes the referent.
- We can create an array of references.
Discussion:
11 comments Page 1 of 2.
Anu said:
3 years ago
Array of references is not allowed, where as reference to array is possible,
int &b[3]=a;
error: declaration of 'b' as array of references
22 | int &b[3]={1,2,3};
| ^
Reference to array:
int a[3] = {1,2,3};
int (&b)[3] =a;
int &b[3]=a;
error: declaration of 'b' as array of references
22 | int &b[3]={1,2,3};
| ^
Reference to array:
int a[3] = {1,2,3};
int (&b)[3] =a;
(2)
Dips said:
3 years ago
It is very useful for me. Thank you all.
Suraj Pawar said:
6 years ago
In my opinion, the array of reference is not possible since.
You need a base address for the array. That means it will be illegal since references are only just another name for a variable, no addresses.
You need a base address for the array. That means it will be illegal since references are only just another name for a variable, no addresses.
(1)
Gowtham said:
6 years ago
What is meant by referent?
Shubham said:
7 years ago
int arr1[3] = {0,1,2};
int (&arr2)[3] = arr1;
for (int index = 0; index<3; ++index)
{
cout << arr2[index];
}
Here, arr2 is referring to arr1.
int (&arr2)[3] = arr1;
for (int index = 0; index<3; ++index)
{
cout << arr2[index];
}
Here, arr2 is referring to arr1.
(1)
Vishal said:
7 years ago
Hi please give an explanation about reference given in the sentence.
Madhuri said:
8 years ago
It is very useful for me. Thank you all.
RamD said:
1 decade ago
@Krish.
Don't you think the program that you have created is for reference to array?
Don't you think the program that you have created is for reference to array?
Krishna gopal said:
1 decade ago
I apology for my previous comment array of reference is not possible but reference to array is possible.
Krishan gopal said:
1 decade ago
But we can create array of reference also. Given below,
int arr1[3];
int(&arr2)[3]=arr1;
for(int index=0;index<3;++index)
{
cout<<arr2[3];
}
int arr1[3];
int(&arr2)[3]=arr1;
for(int index=0;index<3;++index)
{
cout<<arr2[3];
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers