Bird
0
0

Identify the error in this else-if ladder code snippet:

medium📝 Debug Q6 of 15
C - onditional Statements
Identify the error in this else-if ladder code snippet:
int x = 5;
if (x > 10)
  printf("Greater than 10\n");
else if x > 5 {
  printf("Greater than 5\n");
} else {
  printf("5 or less\n");
}
AMissing parentheses around condition in else if
BMissing semicolon after printf
CIncorrect use of braces in else block
DVariable x not declared
Step-by-Step Solution
Solution:
  1. Step 1: Check else-if syntax

    The else-if condition must be inside parentheses. Here, 'else if x > 5' misses parentheses.
  2. Step 2: Verify other parts

    Semicolons are present after each printf. Braces and variable declaration are correct.
  3. Final Answer:

    Missing parentheses around condition in else if -> Option A
  4. Quick Check:

    Else-if condition needs parentheses [OK]
Quick Trick: Always put conditions in parentheses in else-if [OK]
Common Mistakes:
  • Omitting parentheses in else-if
  • Confusing semicolon necessity
  • Misplacing braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes