Difficulty: Easy
Correct Answer: Error: ++needs a value
Explanation:
Introduction / Context:Unary increment (postfix or prefix) requires a modifiable lvalue because it actually writes back to the operand after computing its value. When an object is declared const, the language forbids modifying it through that identifier. This question checks your understanding by applying the post-increment operator to a const-qualified integer and observing the result at compile time.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Identify operator → i++ requires write-back to i.Check object mutability → i is const → write disallowed.Compilation error occurs; typical messages include 'lvalue required' or 'increment of read-only variable'.Verification / Alternative check:
Replacing i++ with (i + 1) compiles, because that expression does not modify i; it only computes a temporary value.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
Error: ++needs a value
Discussion & Comments