Bird
0
0

Identify the error in this for loop:

medium📝 Debug Q6 of 15
C - Loops
Identify the error in this for loop:
for(int i = 0; i < 5; i++)
    printf("%d ", i)
AIncorrect loop condition syntax
BMissing semicolon after printf statement
CLoop variable not declared
DMissing braces around loop body
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of loop and statements

    The loop syntax is correct, but the printf statement lacks a semicolon at the end.
  2. Step 2: Identify the missing semicolon

    In C, each statement must end with a semicolon; missing it causes a syntax error.
  3. Final Answer:

    Missing semicolon after printf statement -> Option B
  4. Quick Check:

    Missing semicolon causes syntax error [OK]
Quick Trick: Every statement needs a semicolon [OK]
Common Mistakes:
  • Assuming braces are mandatory for single statement
  • Thinking loop condition syntax is wrong
  • Ignoring missing semicolon errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes