pre与M.在C,C ++,Java和与放大器后增量运算符的行为; C# [英] Pre & post increment operator behavior in C, C++, Java, & C#
问题描述
免责声明: 这不是一个真实的例子。正是这些语言是如何工作的只是一个理论问题。的
究竟是什么C / C ++,C#和Java之间的区别,当涉及到邮政和放大器; pre增量操作?
这是我所得到的与VC ++ 10的Java 1.6和C#4
int类型的= 2;
INT B = A + +一个++;
INT C = + A + A + +一个++; + ----- + ------ + ------ + ---- +
| B | C ++ | Java的| C#|
+ ----- + ----- + ------ + ------ + ---- +
| A | 7 | 7 | 7 | 7 |
+ ----- + ----- + ------ + ------ + ---- +
| C | 4 | 4 | 5 | 5 |
+ ----- + ----- + ------ + ------ + ---- +
| B | 15 | 15 | 16 | 16 |
+ ----- + ----- + ------ + ------ + ---- +
Java和C#评估前pressions由左到右,而副作用是可见的立即的
在C ++中,SUBEX pressions的计算顺序是不确定的,并修改两次相同的对象,而无需插入顺序的一点是不确定的行为。
DISCLAIMER: This is not a real-world example. It is just a theoretical question of how these languages work.
What exactly are the differences between C/C++, C#, and Java when it comes to post & pre increment operators?
This is what I get with VC++10, Java 1.6, and C# 4
int a = 2;
int b = a++ + a++;
int c = ++a + a++ + a++;
+-----+------+------+----+
| C | C++ | Java | C# |
+-----+-----+------+------+----+
| a | 7 | 7 | 7 | 7 |
+-----+-----+------+------+----+
| b | 4 | 4 | 5 | 5 |
+-----+-----+------+------+----+
| c | 15 | 15 | 16 | 16 |
+-----+-----+------+------+----+
Java and C# evaluate expressions from left to right, and the side-effects are visible immediately.
In C++, the order of evaluation of subexpressions is unspecified, and modifying the same object twice without an intervening sequence point is undefined behavior.
这篇关于pre与M.在C,C ++,Java和与放大器后增量运算符的行为; C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!