Bird
0
0

Find the error in this nested conditional code:

medium📝 Debug Q6 of 15
C - onditional Statements

Find the error in this nested conditional code:

int n = 5;
if (n > 0)
  if (n < 10)
    printf("In range\n");
  else
    printf("Out of range\n");
AVariable n is not declared
BSyntax error due to missing semicolon
CMissing braces cause else to pair with inner if only
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Analyze else pairing

    Without braces, else pairs with nearest if (inner if).
  2. Step 2: Understand impact

    Outer if has no else, which may cause logic errors.
  3. Final Answer:

    Missing braces cause else to pair with inner if only -> Option C
  4. Quick Check:

    Braces needed to clarify else pairing [OK]
Quick Trick: Always use braces to avoid else ambiguity [OK]
Common Mistakes:
  • Assuming else pairs with outer if
  • Ignoring braces importance
  • Thinking syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes