ExamVeda
Login
Home
Control Flow Statements in C plus plus
?

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

Answer & Solution
Correct Answer: Option B
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 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).