Difficulty: Easy
Correct Answer: All of the above.
Explanation:
Introduction / Context:
References and pointers are both indirection mechanisms, but they differ in semantics and safety. Understanding these differences guides API design, function parameter choices, and helps avoid undefined behavior. This question asks which properties collectively distinguish references from pointers in C++.
Given Data / Assumptions:
Concept / Approach:
A reference must be initialized to refer to a valid object and cannot later be made to refer to a different object; there is no “null reference” in standard C++ (though a reference may be bound to an object with problematic lifetime if misused). Access through a reference uses the same syntax as for the object itself, removing the need for explicit * dereferencing at use sites. By contrast, pointers can be null, can be reseated, and require * to access the pointed-to object (and -> for members).
Step-by-Step Solution:
Verification / Alternative check:
Try compiling code that assigns a new address to a reference after initialization; it fails. Try taking the address of a reference variable; you get the address of the referent, not a separate pointer object. Using the reference in expressions behaves like using the original object.
Why Other Options Are Wrong:
Any single statement alone is incomplete; all three together describe the full semantic distinction.
Common Pitfalls:
Final Answer:
All of the above.
Discussion & Comments