首页 > 应用开发 > > C语言运算符之逻辑运算符
编程基础知识分享
下表是显示了C语言支持的所有逻辑运算符。 假设变量a,变量b。
创建源文件:mlogical_operators.c,代码如下:
#include <stdio.h>
main() {
int a = 5;
int b = 30;
int c ;
if ( a && b ) {
printf("Line 1 - Condition is true\n" );
}
if ( a || b ) {
printf("Line 2 - Condition is true\n" );
}
/* lets change the value of a and b */
a = 0;
b = 20;
if ( a && b ) {
printf("Line 3 - Condition is true\n" );
} else {
printf("Line 3 - Condition is not true\n" );
}
if ( !(a && b) ) {
printf("Line 4 - Condition is true\n" );
}
}
执行上面代码,得到以下结果:
Line 1 - Condition is true
Line 2 - Condition is true
Line 3 - Condition is not true
Line 4 - Condition is true
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4822/viewspace-3125693/ ,如需转载,请注明出处,否则将追究法律责任。