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++?
A. 00 11 22 33 21 01
B. 00 10 20 01 11 22
C. 00 01 10 11 20 21
D. Compilation error
Answer: Option C
Solution (By Examveda Team)
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
Join The Discussion
Comments (1)
What is the syntax for the 'if' statement in C++?
A. if (condition) then statement;
B. if (condition) then { statement; }
C. if { condition } then { statement; }
D. if (condition) { statement; }
What is the purpose of the 'else' statement in C++?
A. Executes after the 'if' block
B. Executes before the 'if' block
C. Executes when the 'if' condition is false
D. Executes regardless of the 'if' block
What is the correct syntax for the 'switch' statement in C++?
A. switch (expression) { case constant1: statement1; case constant2: statement2; }
B. switch (expression) { case constant1: statement1; break; case constant2: statement2; break; default: defaultStatement; }
C. switch (expression) { case constant1: statement1; default: defaultStatement; }
D. None of the above
A. Compilation error
B. HelloGoodbye
C. Hello
D. Goodbye

How do we arrive at this answer. From a beginner