自增自减运算符放在同一句输出时

img


为什么输出

```c
#include <stdio.h>

void main()
{
int i=8;
printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--);
}

```是从8开始啊

你这段代码属于undefined behavior,因为C/C++语言标准没有规定函数参数的计算顺序,所以编译器可以按任意顺序来计算每个参数值,这就使得你的代码在不同编译器上得到的结果可能不一样。

From https://en.cppreference.com/w/c/language/eval_order

Order of evaluation of the operands of any C operator, including the order of evaluation of function arguments in a function-call expression, and the order of evaluation of the subexpressions within any expression is unspecified (except where noted below). The compiler will evaluate them in any order, and may choose another order when the same expression is evaluated again.

因为print运算顺序是从右向左