ITPub博客

首页 > 应用开发 > > C语言运算符之逻辑运算符

C语言运算符之逻辑运算符

作者:nt1979 时间:2019-11-14 17:58:17 0 删除 编辑

编程基础知识分享 



下表是显示了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/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 什么是python函数
请登录后发表评论 登录
全部评论

注册时间:2019-08-05

  • 博文量
    318
  • 访问量
    17318