I = ++ i和++ I的区别 [英] Difference between i = ++i and ++i
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/949433/could-anyone-explain-these-undefined-behaviors-i-i-i-i-i-etc\">Could谁能解释这些不确定的行为,(I = I + + + + I,I = I ++等&hellip;)
什么是 I = ++我之间的区别;
和 ++我;
,其中 I
是值的整数 10
?
What is the difference between i = ++i;
and ++i;
where i
is an integer with value 10
?
据我既做两个前pressions完成 I = 11 $后递增
I
即同样的工作C $ C>。
According to me both do the same job of incrementing i
i.e after completion of both the expressions i =11
.
推荐答案
调用未定义行为而 ++我;
没有。
C ++ 03 [第5/4]说:的previous和下一个序列点之间的标量对象,由一个前$ p的评价已经修改最多的一次存储的值$ pssion
。
C++03 [Section 5/4] says Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression
.
在 I = ++我
I
正在修改两次[pre-增量和分配]没有任何干预序列点,这样的行为在C和C ++中。
In i = ++i
i
is being modified twice[pre-increment and assignment] without any intervening sequence point so the behaviour is Undefined in C as well as in C++.
但 I = ++我
很好用C ++定义0X:)
However i = ++i
is well defined in C++0x :)
这篇关于I = ++ i和++ I的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!