Bird
0
0

Find the error in this if-else code:

medium📝 Debug Q7 of 15
C - onditional Statements
Find the error in this if-else code:
int a = 5;
if a == 5 {
  printf("Five\n");
} else {
  printf("Not five\n");
}
AMissing braces around else
BMissing semicolon after if
CMissing parentheses around if condition
DCannot compare int with ==
Step-by-Step Solution
Solution:
  1. Step 1: Check if statement syntax

    The condition in an if statement must be enclosed in parentheses: if (a == 5).
  2. Step 2: Verify other syntax

    Semicolons after if are not used; braces around else are present; == is valid for int comparison.
  3. Final Answer:

    Missing parentheses around if condition -> Option C
  4. Quick Check:

    If condition syntax = A [OK]
Quick Trick: If conditions always need parentheses [OK]
Common Mistakes:
  • Omitting parentheses in if
  • Adding semicolon after if
  • Misusing == operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes