Nonsense not much to say, directly on the code.
PackageCom.coshaho.learn;/*** * Operatorlearn.java Create on 2016-11-13 8:38:15 * class function Description: In-depth understanding + + operator * * Copyright:copyright (c) 201 3 * Company:coshaho * @Version 1.0 * @Author Coshaho*/ Public classOperatorlearn {//Unary operator, assignment operator, trinocular operator from right to left, other operators from left to right//++x steps: 1. return x+1;2. Execute x = x + 1;//X + + steps: 1. Return to x;2. execute × = x + 1; Public Static voidMain (string[] args) {intx = 1; //Step 1. Calculate y (default value 0); //Step 2. (x + +) returns a value of × to the temporary variable C, which is 1; //Step 3. x = x + 1,x is 2; //Step 4. Calculate x,x to 2; //Step 5. y = Temp variable c + 2 = 1 + 2 = 3. inty = (x + +) +x; System.out.println ("x =" +x); System.out.println ("y =" +y); X= 1; //Step 1. Calculate y (default value 0); //Step 2. (++x) returns the X+1 value to the temporary variable C, which is 2; //Step 3. x = x + 1,x is 2; //Step 4. Calculate x,x to 2; //Step 5. y = Temp variable c + 2 = 2 + 2 = 4.y = (++x) +x; System.out.println ("x =" +x); System.out.println ("y =" +y); X= 1; //Step 1. Calculate y (default value 0); //Step 2: Calculate x, for 1; //Step 3. (++x) returns the X+1 value to the temporary variable C, which is 2; //Step 4. x = x + 1,x is 2; //Step 5. y = 1 + c = 1 + 2 = 3.y = x + (+ +)x); System.out.println ("x =" +x); System.out.println ("y =" +y); X= 1; //Step 1. Calculate y (default value 0); //Step 2: Calculate x, for 1; //Step 3. (x + +) returns a value of × to the temporary variable C, which is 1; //Step 4. x = x + 1,x is 2; //Step 5. y = 1 + c = 1 + 1 = 2.y = × + (X + +); System.out.println ("x =" +x); System.out.println ("y =" +y); X= 1; //1. Calculate x, which is 1;//2. Calculation (x + +) returns 1 to the TEMP variable C//3.x = x + 1, 2;//4. Calculate x = 1 + c = 1 + 1 = 2;× + = (x + +); System.out.println ("x =" +x); int[] xx = {1,3}; inti = 0; Xx[i+ +] *= 2; System.out.println ("Xx[0] =" + xx[0] + ", xx[1] =" + xx[1]); XX=New int[]{1,3}; I= 0; Xx[i+ +] = xx[i++] * 2; System.out.println ("Xx[0] =" + xx[0] + ", xx[1] =" + xx[1]); /*** Output * x = 2 y = 3 x = 2 y = 4 x = 2 y = 3 x = 2 y = 2 x = 2 Xx[0] = 2, xx[1] = 3 Xx[0] = 6, xx[1] = 3 */ }}
Java unary operator + + explanation