Difficulty: Easy
Correct Answer: Only 1 is correct.
Explanation:
Introduction / Context:
References in C++ provide aliasing. When you modify a reference, you are actually modifying the underlying object. However, the language imposes restrictions on forming certain compound types with references, notably arrays. This question asks you to separate these two facts.
Given Data / Assumptions:
Concept / Approach:
Because a reference is an alias, any assignment or mutation using the reference applies to the same storage as the original variable. Conversely, arrays of references are not allowed because references are not objects with independent identity and cannot exist “unbound.” If you need array-like behavior, use arrays of pointers or std::reference_wrapper to emulate collections of references.
Step-by-Step Solution:
Verification / Alternative check:
Demonstrate: int x = 7; int& rx = x; rx++; Then x == 8. Attempt to compile int& arr[3]; and observe a compile-time error. Use std::reference_wrapper<int> if you need an array-like container of referents.
Why Other Options Are Wrong:
Only 2 — wrong because arrays of references are disallowed.
Both correct — fails due to statement 2.
Both incorrect — fails because statement 1 is true.
Common Pitfalls:
Final Answer:
Only 1 is correct.
Discussion & Comments