下表是显示了C语言支持的所有逻辑运算符。 假设变量a,变量b。
创建源文件:mlogical_operators.c,代码如下:
#include
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