Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q6 of 15
C - onditional Statements
Find the error in this code snippet:
#include <stdio.h>
int main() {
    int num = 10;
    if num > 5 {
        printf("Greater than 5\n");
    } else {
        printf("Not greater\n");
    }
    return 0;
}
AMissing semicolon after printf
BMissing parentheses around the condition in the if statement
CIncorrect use of else keyword
DVariable num is not declared
Step-by-Step Solution
Solution:
  1. Step 1: Check the if statement syntax

    In C, the condition must be inside parentheses: if (condition).
  2. Step 2: Identify the error in the code

    The code uses if num > 5 without parentheses, which is a syntax error.
  3. Final Answer:

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

    if condition must be in parentheses [OK]
Quick Trick: Always put condition inside parentheses in if [OK]
Common Mistakes:
  • Omitting parentheses in if
  • Thinking semicolon is missing after printf
  • Confusing else syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes