#include
int main()
{
int a = 2;
printf("--a + a--:%d a-- + a--:%d\n",--a+a--,a--+a--);
}
codeblocks上是 -2 4
手机c4是 2 -1
但是正确的好像是 -3 3
这个叫做未定义行为(undefined behavior)
http://blog.csdn.net/fangyi86/article/details/6008395
不同的编译器对于语言规范没有规定的情形,可以编译出不同的结果。
自增自减运算放在同优先级的四则运算表达式中就是一个典型的未定义行为。
再比如说数组越界、变量初始值、函数参数求值顺序等等都可以算未定义行为。
正常现象。
You cannot rely on the order of execution of side effects to arguments to a function. In this case the 2 compilers are executing the side effects in a different order, producing different results.
自增自减运算就是典型的产生side effects的情形。