C++ Programming - References - Discussion

Discussion Forum : References - General Questions (Q.No. 4)
4.
Which of the following statements is correct?
  1. Change a reference changes the referent.
  2. We can create an array of references.
Only 1 is correct.
Only 2 is correct.
Both 1 and 2 are correct.
Both 1 and 2 are incorrect.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
11 comments Page 1 of 2.

Anu said:   1 year 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;
(2)

Dips said:   2 years ago
It is very useful for me. Thank you all.

Suraj Pawar said:   5 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.
(1)

Gowtham said:   5 years ago
What is meant by referent?

Shubham said:   5 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.
(1)

Vishal said:   6 years ago
Hi please give an explanation about reference given in the sentence.

Madhuri said:   7 years ago
It is very useful for me. Thank you all.

RamD said:   10 years ago
@Krish.

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];
}


Post your comments here:

Your comments will be displayed after verification.