Bird
0
0

Find the error in this else-if ladder:

medium📝 Debug Q7 of 15
C - onditional Statements
Find the error in this else-if ladder:
int y = 12;
if (y < 10) {
  printf("Less than 10\n");
} else if (y < 20)
  printf("Less than 20\n");
else
  printf("20 or more\n");
}
AMissing parentheses in else if
BExtra closing brace at the end
CNo error, code is correct
DMissing semicolon after printf
Step-by-Step Solution
Solution:
  1. Step 1: Check braces balance

    There is an extra closing brace '}' at the end that does not match any opening brace.
  2. Step 2: Verify other syntax

    Semicolons are present, parentheses in else-if are correct, so no other errors.
  3. Final Answer:

    Extra closing brace at the end -> Option B
  4. Quick Check:

    Braces must be balanced; extra brace causes error [OK]
Quick Trick: Count opening and closing braces carefully [OK]
Common Mistakes:
  • Ignoring extra braces
  • Assuming missing semicolon error
  • Confusing parentheses usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes