算術運算符:
下表是顯示了C語言支持的所有算術運算符。假設變量A的值是10,變量B的值是20。
創建源代碼文件:marithmetic_operators.c,代碼如下:
#include <stdio.h>
void main() {
int a = 21;
int b = 10;
int c ;
c = a b;
printf("Line 1 - Value of c is %d\n", c );
c = a - b;
printf("Line 2 - Value of c is %d\n", c );
c = a * b;
printf("Line 3 - Value of c is %d\n", c );
c = a / b;
printf("Line 4 - Value of c is %d\n", c );
c = a % b;
printf("Line 5 - Value of c is %d\n", c );
c = a ;
printf("Line 6 - Value of c is %d\n", c );
c = a--;
printf("Line 7 - Value of c is %d\n", c );
}
執行上面的代碼,得到如下結果:
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 21
Line 7 - Value of c is 22
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!