C语言自增自减输出顺序

img


这是个什么顺序呢?只知道函数传参有自增减是从右到左,输出里的是按什么来的呀?

a++ 是先进行a相关语句的执行 再进行自增1
++a 是先进行自增1 再执行相关语句

举个例子来说吧:
int a=1,b=2;
printf("%d%d",a++,b++);//输出值:a=1 b=2


int a=1,b=2;
printf("%d%d",++a,++b);//输出值:a=2 b=3

希望对题主有所帮助!可以的话,帮忙点个采纳!

i++是先用后加,++i是先加后用

不要写这种代码,这种代码在不同编译器上得到的结果不一样。因为C/C++语言标准没有规定函数参数的计算顺序,编译器可以按任意顺序计算参数值。
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.

printf里的是右到左