Difficulty: Easy
Correct Answer: a += 1;
Explanation:
Introduction / Context:
Incrementing a variable by 1 is basic, yet syntax traps are common. This question checks your understanding of valid increment expressions in C#.
Given Data / Assumptions:
Concept / Approach:
Valid increment forms include the compound assignment and additive assignment. Expressions must be syntactically correct and semantically add one to the existing value of a.
Step-by-Step Solution:
Verification / Alternative check:
Compile each form. Only a += 1; and a = a + 1; compile and behave correctly.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing assignment with increment and misusing ++ with extra tokens.
Final Answer:
a += 1; (Note: a = a + 1; is also correct; among the given choices, both B and D increment by 1. If you must choose one, pick a += 1;.)
Discussion & Comments