About Lianga and Lian-minus: http://blog.csdn.net/ieayoio/article/details/46431843
Here's a code that's universally understood:
public static void Main (string[] args) {int a=3; SYSTEM.OUT.PRINTLN (a++ + 1);//4system.out.println (a);//4system.out.println (++a + 1);//6}
a++ is calculated first and then + +, and ++a opposite
In fact, in fact, in every step of the use of the rules we said above, here a++ + ++a equals 8, is because 3+5 equals 8, the first encounter a++ when the value of a is 3, but the execution after playing the value becomes 4, and after the operation of ++a becomes 5
But look at the following procedure:
Because there is a space in the middle, is understood in order to add, so now is 3+4 equals 7
If the above understanding, the following piece of code is very easy:
Actually is 4+5=9, because is ++a, therefore will first + +, waits for the computation to the second ++a, a already is 4, so the answer is 9
Let's look at a more complicated example:
Here is the analysis:
Summary: So basically still master a++ is first to participate in the calculation and then ++,++a is the first + + to participate in the calculation, but the value of a change is not a formula after the change, but every step after the calculation is likely to change
It is obvious that + + operation to participate in the ordinary operation of the readability will be very poor, in addition, because the impact of the added, may inadvertently is completely to make a result, so try not to let + + operations involved in too complex operations, can choose to replace him in the way
a++ and ++a in Java are analyzed in more complex operations