Java unary operator + + explanation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.