Bird
0
0

What is the output of the following C code?

medium📝 Predict Output Q4 of 15
C - Loops
What is the output of the following C code?
for(int x = 0; x < 2; x++) {
for(int y = 0; y < 3; y++) {
printf("%d-%d ", x, y);
}
}
A0-0 1-0 0-1 1-1 0-2 1-2
B0-0 0-1 0-2 1-0 1-1 1-2
C0-0 1-0 2-0 0-1 1-1 2-1
D0-0 0-1 1-0 1-1 2-0 2-1
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop ranges

    Outer loop x runs from 0 to 1 (2 iterations), inner loop y runs from 0 to 2 (3 iterations).
  2. Step 2: Determine output order

    For each x, y runs fully from 0 to 2, printing "x-y ".
  3. Step 3: Write output sequence

    Outputs: 0-0 0-1 0-2 1-0 1-1 1-2
  4. Final Answer:

    0-0 0-1 0-2 1-0 1-1 1-2 -> Option B
  5. Quick Check:

    Inner loop completes fully for each outer loop iteration [OK]
Quick Trick: Inner loop completes fully before outer loop increments [OK]
Common Mistakes:
  • Mixing order of printed values
  • Assuming loops run in parallel
  • Miscounting loop iterations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes