C++ reference reseating: which statement is correct? Choose the rule that governs whether a reference can later refer to another variable.

Difficulty: Easy

Correct Answer: Once a reference variable has been defined to refer to a particular variable it cannot refer to any other variable.

Explanation:


Introduction / Context:
One of the most important properties of C++ references is that, after initialization, they are bound permanently to the same object. This question checks your understanding of that non-reseating rule.



Given Data / Assumptions:

  • We are discussing lvalue references such as 'int &r = x;'
  • Initialization happens at the point of declaration.
  • No later reassignment syntax exists for references.



Concept / Approach:
A reference is an alias. After binding, it always denotes the same object. Assigning to the reference assigns to the referent, not to the binding. By contrast, pointers can be reseated to point elsewhere; references cannot. Also, '&&' denotes rvalue references in declarations (type&&), not the general indicator that 'this entity is a reference' in all contexts.



Step-by-Step Solution:
1) Bind: 'int a; int &r = a;'2) Attempt 'r = b;' does not reseat; it assigns a = b.3) There is no syntax to make r refer to a different object later.4) Therefore, option C states the correct rule.



Verification / Alternative check:
Compile a test where you try to 'rebind' the reference via assignment. Observe it simply writes into the original variable.



Why Other Options Are Wrong:
A: contradicts the language rule; only pointers can be reseated.B: '&&' is the syntax for rvalue references in type declarations, not a general indicator as written.D: references must be initialized at declaration; you cannot leave them uninitialized and fill later.



Common Pitfalls:
Confusing assigning through a reference (affects the referent) with changing what the reference refers to (impossible).



Final Answer:
Once a reference variable has been defined to refer to a particular variable it cannot refer to any other variable.


Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion