Given:
int r=1;
r=r++ + r++ + r++;
System.out.println("r:" + r);
Why is this returning 6 instead of 7.
I can get the order of how the above is evaluated e.g. 1 + 2 + 3 = 6 but not sure why the last 'r++' is not reflected in the system.out.
Looking at below:
int i=1;
int r=i++ + i++ + i++;
System.out.println("r:" + r);
System.out.println("i:" + i);
in this example 'r' is 6 and 'i' is 4, as it should be, and the last 'i++' is reflected in the result printed by System.out.