Difficulty: Easy
Correct Answer: Only 2 is correct.
Explanation:
Introduction / Context:
This question checks precise understanding of C++ references versus pointers. A reference acts as an alias to an existing object and is subject to strict binding rules. Many beginners mistakenly equate references with “constant pointers,” which leads to confusion about reseating, nullability, and dereferencing syntax.
Given Data / Assumptions:
Concept / Approach:
A reference must be initialized to a valid object at its point of declaration and cannot be reseated to name a different object afterward. That is why references are often considered “aliases.” While some teaching materials loosely compare a reference to a “const pointer,” this is only an analogy and not a type identity. Pointers are objects with their own address and can be reassigned; references are not objects on their own and participate directly in expressions as the referred-to entity. Hence, it is more accurate to state “a reference is not a constant pointer.”
Step-by-Step Solution:
Verification / Alternative check:
Consider int x = 5; int& r = x; int y = 9; Attempting r = y; assigns to x through the reference; it does not reseat r. Taking &r yields the address of x, not a separate “reference object,” reinforcing that a reference is not a pointer variable.
Why Other Options Are Wrong:
Only 1 is correct — wrong; reseating is not permitted.
Both correct — wrong because statement 1 fails.
Both incorrect — wrong because statement 2 is accurate.
Common Pitfalls:
Final Answer:
Only 2 is correct.
Discussion & Comments