86.9k views
3 votes
What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; }

0
1
2
3
4
0 1 2 3 4
0 1 2 3 4 5
This is an infinite loop

1 Answer

1 vote

Answer:

The loop will display the following output:

0

1

2

3

4

The loop will iterate as long as the value of x is less than 5. On each iteration, the value of x is displayed using cout, and then x is incremented by 1 using the x++ operator. This process continues until the value of x is no longer less than 5, at which point the loop terminates and the program continues to execute any code that follows the loop. The output of the loop will be a series of numbers, starting at 0 and ending at 4, with each number displayed on a separate line

User John Farrelly
by
6.9k points