Difficulty: Medium
Correct Answer: 101
Explanation:
Introduction / Context:
This question mixes boolean defaults, nested if statements, and an assignment used as a condition. You must carefully track state changes to b1, b2, and x as execution proceeds.
Given Data / Assumptions:
Concept / Approach:
Because b1 and b2 start false, the first two if conditions are true, entering the inner block. Inside, b1 becomes true and x is incremented to 1. The comparison 5 > 6 is false. The next if (!b1) is false because b1 is now true. The else-if executes an assignment (b2 = true) which evaluates to true, so that branch runs and adds 100 to x.
Step-by-Step Solution:
Verification / Alternative check:
If the code had used == instead of = at line 19, the result would depend on prior b2, but here the assignment guarantees the branch executes.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing assignment with comparison and overlooking that assignment expressions evaluate to the assigned value.
Final Answer:
101
Discussion & Comments