Does (++i)+(++i) have the defined behavior in Java

57 Views Asked by At
int i=1;
int n = (++i)+(++i);

In C++ the above code has undefined behavior. I want to know in Java, does it have defined behavior and give the expected answer n=5 in this case. In Java, the order of evaluation between two sides of + is defined. The key point is whether Java would always produce a temporary value 2 for the first ++i.

0

There are 0 best solutions below