1, arithmetic operators is a numeric type variables operation
2, arithmetic operators List
3, increment: ++
Use as a separate statement: i ++ ++ i and are fully equivalent to i = i + 1
Use as an expression: i ++ increment after the first assignment
++ i first increase since the assignment
. 1 #include <stdio.h> 2 . 3 void main () { . 4 Double D1 = 10 / . 4 ; . 5 Double D2 = 10.0 / . 4 ; . 6 the printf ( " D1 =% F, F D2 =% \ n- " , D1, D2); // 2.000000 2.500000 . 7 // 10 / = 2.5. 4 ==> truncate ==> 2 ==> 2.000000 8 // If desired decimals, participation operand must float . 9 10 . 11 12 is int RES1 = 10 % . 3 ; 13 is int res2 = -10 % 3; 14 int res3 = 10 % -3; 15 int res4 = -10 % -3; 16 printf("res1=%d,res2=%d,res3=%d,res4=%d\n", res1, res2, res3,res4); //1 -1 1 -1 17 //取模公式:a%b=a-a/b*b 18 //res1=10-10/3*3=1 19 //res2=-10-(-10)/3*3=-1 20 //res3=10-10/(-3)*(-3)=1 21 //res4=-10-(-10)/(-3)*(-3)=-1 22 23 24 25 int i = 10; 26 int j = i++; //运算规则是 int j=i; i=i+1; =>j=10 i=11 27 int k = ++i; //int k=i+1; i=i+1; => k=12 i=12 28 printf("i=%d,j=%d,k=%d", i, j,k); //12 10 12 29 30 }
Details Description:
① In addition to the number "/", and its decimal integer division In addition there is a difference, when doing integer division between, leaving only the integer part and the fractional part is discarded.
② When a modulo number, may be equivalent to a% b = aa / b * b, so that we can see the nature of a modulo operation
③ When the increment as a separate language, whether it is i ++ or ++ i, is the same. i = i + 1
④ When the self-energizing used as an expression equivalent j = ++ i i = i + 1 j = i + 1
⑤ When the self-energizing used as an expression j = i ++ equivalents j = i; i = i + 1;