, , , postfix (expr ++). , , .
int i = 1;
System.out.println(i += i++);
, , :
i++; // i is now 2 for the rest of this statement and the program
i = 1 + 1; // i is assigned again
, postfix, , i.
, , :
int i = 2;
System.out.println(i += i++);
System.out.println(i);
:
int i = 2;
System.out.println(i = i + i++ + i--);
System.out.println(i);
The second line assigns i. The first self is 2, the next self is also 2, but now the third self is 3, because I ++ changed the value of i. As before, i-- will not have any effect on i, because it will be rewritten with i = 2 + 2 + 3.
int i = 1;
System.out.println(i = i++ + i);
System.out.println(i);
source
share