0

我通过编译器检查了这两个:

这个的输出是 10

    int count = 0; 
    for(int i=0; i < 10; ++i){ 
            count=++count;
    }
    cout << count; 

我不明白为什么 this(++count 变成 count++) 的输出是 0

    int count = 0; 
    for(int i=0; i < 10; ++i){ 
            count=count++;
    }
    cout << count; 
4

1 回答 1

4

        count=++count;

        count=count++;

count当您在没有中间序列点的情况下进行修改时,这两个程序都会遇到未定义的行为。请注意,=运算符不会引入序列点。

必读 UB ;-)

C++ 中的未定义行为和序列点

于 2013-10-22T18:50:49.183 回答