Bird
0
0

Find the error in this if-else code snippet:

medium📝 Debug Q14 of 15
C - onditional Statements
Find the error in this if-else code snippet:
int a = 3;
if a > 0
    printf("Positive\n");
else
    printf("Non-positive\n");
AMissing semicolon after if statement
BMissing parentheses around condition in if statement
CMissing braces around printf statements
DIncorrect else keyword
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of if condition

    In C, the condition in an if statement must be inside parentheses (). Here, it is missing.
  2. Step 2: Verify other parts

    Semicolons after printf are present, braces are optional for single statements, and else keyword is correct.
  3. Final Answer:

    Missing parentheses around condition in if statement -> Option B
  4. Quick Check:

    if condition needs parentheses ( ) [OK]
Quick Trick: Always put condition inside parentheses ( ) [OK]
Common Mistakes:
  • Forgetting parentheses in if condition
  • Thinking braces are always required for single statements
  • Misplacing else keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes