Difficulty: Medium
Correct Answer: b = 100 c = 200
Explanation:
Introduction / Context:
This question probes operator precedence and associativity between logical NOT (!) and relational operators (>=). It tests whether you know that unary ! is applied before the comparison.
Given Data / Assumptions:
Concept / Approach:
In C, unary operators like ! have higher precedence than relational operators like >=. Therefore the expression is parsed as (!a
) >= 400, not as !(a >= 400). Since a is 500 (nonzero), !a is 0. Then 0 >= 400 is false, so the body of the if does not execute.
Step-by-Step Solution:
Compute !a: !500 → 0.Compare 0 >= 400 → false.Therefore b remains 100.c is set to 200.printf prints “b = 100 c = 200”.
Verification / Alternative check:
Parenthesize as !(a >= 400)
(which evaluates to false) to see explicitly the same result. Change a to 0 to test the true branch: !0 is 1, and 1 >= 400 is false; still no assignment to b.
Why Other Options Are Wrong:
Claims that b becomes 300 ignore precedence; “garbage” for c is invalid because c is definitely assigned before printing.
Common Pitfalls:
Misreading the expression as !(a >= 400); overlooking that !a yields 0 or 1 only; assuming side effects on a.
Final Answer:
b = 100 c = 200
Discussion & Comments