ExamVeda
Login
Home
Control Flow Statements in C plus plus
?

What will be the output of the following code: for (int i = 0; i < 3; ++i) { for (int j = 0; j < 2; ++j) { cout << i << j << " "; } } in C++?

Answer & Solution
Correct Answer: Option D
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Saad Mansoor
Saad Mansoor 8 months ago
The given answer (Option D: 00 01 10 11) is incorrect.

Let’s evaluate the nested loops:

Outer loop: i runs from 0 to 2
Inner loop: j runs from 0 to 1

Execution order:

i = 0
j = 0 → prints 00
j = 1 → prints 01

i = 1
j = 0 → prints 10
j = 1 → prints 11

i = 2
j = 0 → prints 20
j = 1 → prints 21

Final output:
00 01 10 11 20 21

Since none of the given options match this output, the correct answer is not listed.