Question 17
Back to Exercise
Without braces, in if (a) if (b) x(); else y();, which if does the else belong to?
- A The first if (a)
- B The nearest if (b) Correct
- C Both
- D It is a compile error
Correct Answer: Option B
An else binds to the nearest unmatched if – the "dangling else". Braces make intent explicit.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!