Question 3
Back to Exercise
In if (a) if (b) s1; else s2; (no braces), which if does the else belong to?
- A if (a)
- B if (b) – the nearest unmatched if Correct
- C Both
- D It is a syntax error
Correct Answer: Option B
An else always pairs with the closest preceding if that has no else yet. Indentation has no meaning to the compiler; add braces to say what you mean.
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!