the question is what is the final value of x, not what is the last value printed out by the loop. if you print 'x' again after the loop ends, you'll see the final value of 'x' is 10
#include <iostream>
using namespace std;
void main()
{
for (int x=0; x<10;x++)
{
cout << x <<endl;
}
cout <<endl<<endl; //show it seperated from the loop output
cout <<"the final value of x is: "<< x <<endl;
return;
}




Reply With Quote