Java increment, decrement

i++/i--

  Using the first value of the variable, and then change the value of the variable;

++i/--i

  The first table value of the variable, and then use the value of the variable;

When learning Java was not thinking in java principle of variable increment, today met a java title, a bit ignorant: 
int
i = 0 ; i = i ++;

  The final value of the variable i in the end is still to maintain it becomes 1 to 0 it?

  java variable increment, decrement actually realized using the intermediate variable as a temporary buffer.

To i ++ example:

1     public static void main(String[] args) {
2         int i = 0;
3         int j = i++;
4     }

In fact, the above code is equivalent to:

    public static void main(String[] args) {
        int i = 0;
        int temp = i;
        i += 1;
        int j = temp;
    }

Therefore, i = i ++ i is the result of the value remains unchanged.

static void main public (String [] args) { 
int I = 0;
I = I ++;
}

actually equal to
public static void main(String[] args) {
int i = 0;
int temp = i;
i += 1;
i = temp;
}

 

Guess you like

Origin www.cnblogs.com/KenBaiCaiDeMiao/p/11692110.html