Bird
0
0

Find the error in this C code snippet:

medium📝 Debug Q14 of 15
C - onditional Statements
Find the error in this C code snippet:
int num = 7;
if num > 5 {
    printf("Yes\n");
} else {
    printf("No\n");
}
AMissing parentheses around the condition
BMissing semicolon after if statement
CIncorrect use of else keyword
DVariable num not declared
Step-by-Step Solution
Solution:
  1. Step 1: Check the if statement syntax

    The condition in an if statement must be inside parentheses in C.
  2. Step 2: Identify the error

    The code uses if num > 5 { ... } without parentheses, which is invalid syntax.
  3. Final Answer:

    Missing parentheses around the condition -> Option A
  4. Quick Check:

    If condition needs ( ) in C [OK]
Quick Trick: Always put condition inside ( ) for if [OK]
Common Mistakes:
  • Forgetting parentheses in if condition
  • Adding semicolon after if line incorrectly
  • Misplacing braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes