in the In high-level languages such as Java and C, the function of self-increment and decrement is basically the same, and the variable itself is added one or minus one. The following is a description of the self-increment, which is similar to the self-reduction.
The self-increment operator (+ +) has two forms of writing, one before the variable: + + num;
The other is num++ after the variable ; they work the same, but the priorities vary greatly.
Note: The priority represents the order in which the operator executes, and the higher the precedence, the first execution. Baidu Encyclopedia priority table is as follows:
Code Demo:
Public class Test {
Public Static void Main (string[] args) {
int a = 1;
int b = 0;
b = a++;// equivalent to b=a; a++;
System. out. println ("a=" + A + ", b=" + b);
System. out. println ("===== Gorgeous split line =====");
A = 1;//re-assigned to a value of 1
b = 0;//re-assigned to a value of 0
b = ++a;// equivalent to a++;b = A;
System. out. println ("a=" + A + ", b=" + b);
}
}
Output Result:
A=2,b=1
===== Gorgeous split-line =====
a=2,b=2
pre-Gaga priority high first operation, after + + priority low after operation, in C language here is the same way of operation.
===========================================================
differences:
Java code:
Public class Test {
Public Static void Main (string[] args) {
int a = 1;
A = a++;
System. out. println (a);// output result is 1
}
}
C Language code:
#include <stdio.h>
void Main () {
int a = 1;
A = a++;
printf ("%d", a);// output result is 2
}
===============================================================
Conclusion:in theIn Java, we can explain, after the addition of a first to add a, and then the value of no operation is assigned to a, the final result a==1.in theC language is in accordance with the priority of the operation, after a low priority, a first assignment to a itself, and then a again Gaga, the final result a==2;
Differences in the self-increment in Java self-increment (+ +) and C languages