这两个程序有什么区别?

Ano*_*mer -9 c++

这两个程序有什么区别?对于第一个程序,我的输出为9,对于第二个程序,我的输出为10。

#include <iostream>

using namespace std; // So we can see cout and endl

int main()
{
    int x = 0; // Don't forget to declare variables

    while ( x < 10 ) { // While x is less than 10
        cout << x << endl;
        x++; // Update x so the condition can be met eventually
    }
    cin.get();
}
Run Code Online (Sandbox Code Playgroud)
#include <iostream>

using namespace std; // So we can see cout and endl

int main()
{
    int x = 0; // Don't forget to declare variables

    while ( x < 10 ) { // While x is less than 10
        x++; // Update x so the condition can be met eventually
        cout << x << endl;
    }
    cin.get();
}
Run Code Online (Sandbox Code Playgroud)

小智 5

在第一个代码块中,您要输出x,然后将其相加,以便输出0-9。在第二个代码块中,在输出x之前将其加1,这样它将为您提供1-10的输出。它基于您将x++in与输出语句相关联的位置