A Place for Latest Exam wise Questions, Videos, Previous Year Papers, Study Stuff for MCA Examinations - NIMCET
Previous Year Question (PYQs)
2
Consider the following code segment:
if (n > 0)
for (i = 0; i < 3; i++)
if (array[i] > 0)
printf("%d\n", array[i]);
else
printf("\n n is negative\n");
Here, ‘else’ is paired with which ‘if’?
Solution
Solution:
In C, **“else” is always paired with the nearest unmatched “if”** (no braces rule).
Here:
- The inner `if (array[i] > 0)` is the **nearest unmatched `if`** before `else`.
So, the `else` is paired with the **second (inner)** `if`.
Online Test Series, Information About Examination, Syllabus, Notification and More.