Let's take the following code:
int[] data = {1, 2, 3};
int pos = 0;
int result = data[pos++] + data[pos++]*data[pos++];
Am I guaranteed that my result
is always 1 + 2*3, i.e. 7, or could a Java compiler or JVM reorder the execution of the data[pos++]
statements such that I, for example, get 3 + 1*2, i.e. 5, since multiplication has priority over addition?
In other words: In a single statement containing multiple ++
-operations on the same variable, am I guaranteed that they are always executed left to right?