Which statement is correct about a const reference in C++?
int x = 10;
const int &ref = x;
Options
-
A.
ref can be used to modify x directly.
-
B.
ref cannot be used to modify x through the reference.
-
C.
ref always stores a separate copy of x.
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
ref cannot be used to modify x through the reference.
Detailed Explanation
Answer: (B) ref cannot be used to modify x through the reference.
A const reference provides read-only access through that reference.
In the example, ref refers to x, but an assignment such as ref = 20 is not allowed because ref is a reference to const.
It does not necessarily create a separate copy of x; it refers to the original object.