Q
In the C code if (a) if (b) s1; else s2;, which if does the else belong to?
-
A
The inner if (b)
-
B
It is a syntax error
-
C
The outer if (a)
-
D
Both
Correct Answer:
A. The inner if (b)
Explanation:
This is the 'dangling else' problem. An else binds to the nearest unmatched if, whatever the indentation suggests.