c语言算术运算符和赋值运算符(C语言运算符之算术运算符)

算术运算符:

下表是显示了C语言支持的所有算术运算符。假设变量A的值是10,变量B的值是20。

c语言算术运算符和赋值运算符(C语言运算符之算术运算符)(1)

创建源代码文件: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

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页