Bird
0
0

Identify the error in this loop control code:

medium📝 Debug Q6 of 15
C - Loop Control Statements
Identify the error in this loop control code:
int i = 0;
while(i < 5) {
  printf("%d ", i);
}
AMissing semicolon after while
BIncorrect printf syntax
CWrong loop condition
DMissing increment of i causing infinite loop
Step-by-Step Solution
Solution:
  1. Step 1: Check loop variable update

    Variable i is never incremented inside the loop, so condition i < 5 is always true.
  2. Step 2: Understand effect of missing increment

    Without increment, loop runs infinitely printing 0 repeatedly.
  3. Final Answer:

    Missing increment of i causing infinite loop -> Option D
  4. Quick Check:

    Loop control needs variable update [OK]
Quick Trick: Always update loop variable to avoid infinite loops [OK]
Common Mistakes:
  • Forgetting to increment loop variable
  • Assuming loop stops automatically
  • Incorrect loop syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes