The difference between i=++i; and i=i++; in java (interview trap questions)

int j = ++i;//Increment i by 1, and assign the result to j, or in other words, calculate ++i first, and then assign
int k = i++;//Calculate the assignment first, assign the value of i to k, i was originally 3, assign 3 to k, and then i increments by 1, i becomes 4
so:

i=++i; is equivalent to the following two statements (a warning occurs during compilation, which is the same as i=i; warning) :

i=i+1;   
i=i;  

i = i++; is equivalent to the following three statements:

int tmp = i;   
i = i + 1;   
i = tmp;  

Guess you like

Origin blog.csdn.net/Mr_zhang66/article/details/113439389