在以下代码中:
int main() {
int i, j;
j = 10;
i = (j++, j+100, 999+j);
cout << i;
return 0;
}
输出为 1010 .
但是不应该是 1009,如
++
应该在使用整个表达式后完成?
最佳答案
逗号运算符是一个序列点:例如,正如在 C++17 标准中所说,
Every value computation and side effect associated with the left expression is sequenced before every value computation and side effect associated with the right expression.
因此,
++
的效果运算符保证在 999+j
之前发生被评估。
关于c++ - 后增量运算符行为 w.r.t 逗号运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61001093/