Join The Discussion

Comments (1)

  1. Saad Mansoor
    Saad Mansoor:
    4 months ago

    The given answer (Option B: 0 1 2 3) is incorrect.

    Let’s trace the code:

    Initially, i = 0
    First iteration: ++i → i becomes 1 → prints 1
    Second iteration: ++i → i becomes 2 → prints 2
    Third iteration: ++i → i becomes 3 → prints 3
    Now i = 3, condition i < 3 is false → loop stops

    Final output:
    1 2 3

    The correct answer is Option A (1 2 3).

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