Bird
0
0

Identify the error in this for loop:

medium📝 Debug Q14 of 15
C - Loops
Identify the error in this for loop:
for(int i = 0; i < 5; i)
    printf("%d ", i);
AMissing semicolon after printf statement
BMissing increment operator in for loop update
CIncorrect loop condition syntax
DVariable i not declared
Step-by-Step Solution
Solution:
  1. Step 1: Examine the for loop update part

    The update section is 'i' without increment operator, so i never changes.
  2. Step 2: Understand the effect of missing increment

    Without 'i++' or similar, the loop runs infinitely or behaves incorrectly.
  3. Final Answer:

    Missing increment operator in for loop update -> Option B
  4. Quick Check:

    Update must change loop variable [OK]
Quick Trick: For loop update must change variable (e.g., i++) [OK]
Common Mistakes:
  • Forgetting to increment loop variable
  • Confusing semicolon placement
  • Assuming variable auto-increments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes