标签:
以下代码的输出结果是什么?
题目1:
int i=10; printf("%d, %d\n", i++, ++i);
题目2:
int i = 3; printf("%d, %d, %d, %d, %d\n", i++, ++i, i, i++, i);
printf参数是从右至左入栈的,故:
What‘s the value of i++ + i++?
It‘s undefined. Basically, in C and C++, if you read a variable twice in an expression where you also write it, the result is undefined. Don‘t do that. Another example is:
v[i] = i++;
Related example:
f(v[i],i++);
Here, the result is undefined because the order of evaluation of function arguments are undefined.
Having the order of evaluation undefined is claimed to yield better performing code. Compilers could warn about such examples, which are typically subtle bugs (or potential subtle bugs). I‘m disappointed that after decades, most compilers still don‘t warn, leaving that job to specialized, separate, and underused tools.
printf("%d, %d\n", i++, ++i)的输出结果是确定的吗???
标签:
原文地址:http://www.cnblogs.com/whl2012/p/5731385.html