下表是顯示了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
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!