(C语言)运算符
1.赋值运算符
a += 5; //a=a+5
a -= 5; //a=a-5
a = 5; //a=a5
a %= 5; //a=a%5
a /= 5; //a=a/5
2.比较运算符
//c语言中0为假 ,1为真
printf("%d\n", 3==4);//0
printf("%d\n", 3 != 4);//1
printf("%d\n", 3 < 4);//1
printf("%d\n", 3 > 4);//0
printf("%d\n", 3 <= 4);//1
printf("%d\n", 3 >= 4);//0
3.逻辑运算符
!非
&& 逻辑与
//非0就为真
int a = 1;
int b = 2;
int c = 0;
printf("%d\n", !a);//0
printf("%d\n", !0);//1
printf("%d\n", !-1);//0
//逻辑&& A && B 必须A和B都为真,整个表达式才为真
//如果A表达式为假,B表达式不执行
printf("%d", a && b);//1
printf("%d", a && c);//0
//因为c为假,所以表达式b++不执行
printf("%d", c && b++);//0
printf("c=%d b=%d",c,b);//c=0 b=2
|| 逻辑或
int a = 0;
int b = 2;
int c = 0;
//逻辑|| A || B 只要A或B有一个为真,整个表达式就为真
//如果A表达式为真,B表达式不执行
printf("%d", a || b);//1
printf("%d", a || c);//0
因为b为真,所以表达式c++不执行
printf("%d", b || c++);//1
printf("c=%d b=%d", c, b);//c=0 b=2