Examveda

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++?

A. 00 11 22 33

B. 00 10 20 01 11

C. Compilation error

D. 00 01 10 11

Answer: Option D


Join The Discussion

Comments (1)

  1. Saad Mansoor
    Saad Mansoor:
    1 month 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.

Related Questions on Control Flow Statements in C plus plus

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