C中的关系和逻辑运算符
关系运算符
关系运算符用于比较C语言中的两个值。它检查两个值之间的关系。如果relationship为true,则返回1。但是,如果relationship为false,则返回0。
这是C语言中的关系运算符表
这是C语言中关系运算符的示例
示例
#include <stdio.h>
int main() {
int x = 10;
int y = 28;
if(x==y)
printf("Both variables are equal\n");
if(x>y)
printf("x is greater than y \n");
if(x<y)
printf("x is less than y \n");
if(x!=y)
printf("x is not equal to y \n");
if(x<=y)
printf("x is lesser or equal to y\n");
if(x>=y)
printf("x is greater or equal to y \n");
return 0;
}输出结果
x is less than y x is not equal to y x is lesser or equal to y
逻辑运算符
逻辑运算符用于执行逻辑运算。它根据条件的结果(真或假)返回0或1。这些运算符用于C语言决策。
这是用C语言编写的逻辑运算符表,
这是C语言中逻辑运算符的示例,
示例
#include <stdio.h>
int main() {
int x = 10;
int y = 28;
int a = 15;
int b = 20;
if(x<y && a==b)
printf("x is less than y AND a is equal to b\n");
if(x<y || a==b)
printf("x is less than y OR a is equal to b\n");
if(!x)
printf("x is zero\n");
return 0;
}输出结果
x is less than y OR a is equal to b
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志