【发布时间】:2012-07-03 12:41:39
【问题描述】:
可能重复:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
Is there any difference between the Java and C++ operators?
为什么一元运算符在 c++ 和 java 中给出不同的结果?
看看这个:
int i = 1;
i = i++ + ++i;
print i (with cout or println)
在 java 中:打印 4
在 c++ 中:打印 5
为什么?
【问题讨论】:
-
这会在 Java 中为我打印
4。 -
这是
undefined behaviour。有很多很多帖子。快速搜索建议从stackoverflow.com/questions/4176328/… 和stackoverflow.com/questions/4638364/… 开始。另请注意,我使用 g++ 得到5。 -
@Keppil 谢谢,但实际上,我不确定引用的评论是否正确,所以删除了我的。
-
耶!对不起@Keppil。版画变了。对不起:-P
标签: java c++ unary-operator