Difficulty: Easy
Correct Answer: i = i + 1
Explanation:
Introduction / Context:
Operators ++ and -- are syntactic sugar in C, C++, Java, and many other languages for common increment/decrement operations. Recognizing their equivalence to explicit assignment helps avoid off-by-one errors and clarifies pre- vs post-increment behavior in expressions.
Given Data / Assumptions:
Concept / Approach:
The core semantics of ++i are to increase the stored value of i by one unit. As a stand-alone statement (++i;) this is equivalent to i = i + 1;. In compound expressions, ++i yields the updated value, while i++ yields the previous value.
Step-by-Step Solution:
Verification / Alternative check:
Consider i = 5; ++i makes i = 6. Using i = i + 1 also makes i = 6. In a context like j = ++i;, j becomes 6; with j = i++; j becomes 5 though i becomes 6 afterward. The update magnitude remains +1.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing pre-increment with post-increment in expressions; assuming ++i always equals i++ in value position—only the side effect on i matches (+1).
Final Answer:
i = i + 1
Discussion & Comments