ExamVeda
Login
Home
Control Flow Statements in C plus plus
?

What is 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 C
Solution:

The code contains a nested for loop structure.

The outer loop iterates with variable i from 0 to 2 (inclusive), and the inner loop iterates with variable j from 0 to 1 (inclusive).

For each iteration of the outer loop (each value of i), the inner loop runs completely, iterating through both values of j.

The output is printed as follows:

When i = 0:
j = 0 → output is 00
j = 1 → output is 01

When i = 1:
j = 0 → output is 10
j = 1 → output is 11

When i = 2:
j = 0 → output is 20
j = 1 → output is 21

Combining all outputs, the final result is:
00 01 10 11 20 21
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Mûtugi Maina
Mûtugi Maina 2 years ago
How do we arrive at this answer. From a beginner