Let consider the execution path step by step.
1 2 3
|
int i = 5 ;
cout << "i is " << i << "\n" ;
|
i is set to 5 and then this value is outputed.
Then there is the loop
1 2 3 4
|
while (i < 9)
{
cout << i++ ;
}
|
As 5 is less than 9 then the control will enter the loop body.
Inside the loop there is
postincrement operator ++. Its value is the value of i
before its incrementing.
So this statement
cout << i++ ;
outputs the value of i that is equal to 5 and after assigns i the new incremented value that is equal to 6. And so on.
In the last iteration of the loop before the statement above i will be equal to 8. This value will be outputed and due to the
postincrement operator ++ i will set to 9.
The condition of the loop
while (i < 9)
will be equal to
false because 9 is not less than 9.
So the loop will be terminated and the control will be passed to the next statements after the loop
1 2
|
cout << endl ;
cout << "i is " << i << "\n" ;
|
They output 9 that is the current value of i.