Self -increment and self-decrement operators in C language self-learning
1 #include <stdio.h> 2 3 int main() 4 { 5 int a= 99 ; 6 printf( " %d\n " ,a++); // First take the value in the operation, then the output is the assigned value of a 99. After the output, the expression starts to operate and then a is 100; 7 printf( " %d\n " ,++a); // The operation is performed first, and the output is the value of a after the execution of the previous line (100) +1 to take the value, and the output result is 101; 8 printf( " %d\n " ,--a); // The first operation is to take the value, and then the output is the value of a after the previous line (101)-1, and then the value is taken. The output is 100; 9 printf( " %d\n " ,a--); //First take the value in the operation, then the output is the value of the previous line a (100), and the expression starts to operate after the output, and the value of a is 99 at this time; 10 printf( " %d\n " ,a+ 1 ); // Note: The value of a is not changed here, so the output result is the value of a in the previous line (99) + 1, and the value of a after the output does not change, so it becomes 99; 11 printf( " %d\n " ,a) ; // The value of a is 99 after the execution of the previous line, so the output value of a here is 99; 12 return 0 ; 13 }
Note: Whether a++ or ++a is equivalent to a=a+1, the value of a is incremented by 1 after the execution of the expression,
whether a-- or --a is equivalent to a=a-1 , After the expression is executed, the value of a is reduced by 1. The
C program is a logical line-by-line operation, and the value is constantly changing after the line-by-line operation, but the difference is whether it is output or not.