Tag: order of evaluation

在递归中使用+ =的Java和C ++中的不同结果

如下非常简单的Java代码具有奇怪的输出,但C和C ++中的相同逻辑代码具有正确的输出。 我尝试使用JDK 1.7和JDK 1.3(相对JRE),奇怪的输出始终存在。 public class Test { public static int sum=0; public static int fun(int n) { if (n == 1) return 1; else sum += fun(n – 1); // this statement leads to weird output // { // the following block has right output // int tmp = fun(n – 1); // […]

Java中保证了从左到右的操作顺序吗?

考虑这个function: public static final int F(int a, int b) { a = a – 1 + b; // and some stuff return a; } JVM的实现是否需要执行- 1 + b之前的- 1 ? 如果我们有一个连接到JVM的系统分析器,我们会看到在+ 1操作之前执行+ b操作吗?

++ i + ++ i + ++ i in Java vs C.

int i=2; i = ++i + ++i + ++i; 哪个更正确? Java的结果为12或C = 13.或者如果不是正确性,请详细说明。

如何在复杂表达式中计算java增量语句

以下代码的输出是什么: int x = 2; x += x++ * x++ * x++; System.out.println(x); 我理解++variableName是预增量运算符,并且variableName的值在表达式中使用之前递增,而variableName++在表达式执行后递增其值。 我想知道的是 – 这个逻辑在这里是如何应用的?