讲解C语言中逻辑和赋值运算符的概念!
首先,让我们了解一下逻辑运算符。
逻辑运算符
这些用于逻辑地组合2个(或)多个表达式。
它们是逻辑AND(&&)逻辑OR(||)和逻辑NOT(!)
逻辑与(&&)
逻辑OR(||)
逻辑非(!)
示例
以下是计算逻辑运算符的C程序-
#include输出结果main (){ float a=0.5,b=0.3,c=0.7; printf("%d\n",(ac));//0// printf("%d\n",(a>=b)&&(b<=c));//1// printf("%d\n",(a==b)||(b==c));//0// printf("%d\n",(b>=a)||(a==c));//0// printf("%d\n",(b<=c)&&!(c>=a));//0// printf("%d\n",!(b<=c)||(c>=a));//1// }
您将看到以下输出-
0 1 0 0 0 1
赋值运算符
它用于为变量赋值。
类型
赋值运算符的类型是-
简单赋值
复合赋值
a=10"a=a-10
程序
下面给出的是复合赋值运算符的C程序-
#include输出结果int main(void){ int i; char a='h'; printf("enter the value of i:\n"); scanf("%d",&i); printf("print ASCII value of %c is %d\n", a, a); a += 5; printf("print ASCII value of %c is %d\n", a, a); a *= a + i; printf("a = %d\n", a); a *= 3; printf("a = %d\n", a); a /= 2; printf("a = %d\n", a); a %= 4; printf("a = %d\n", a); return 0; }
您将看到以下输出-
enter the value of i: 3 print ASCII value of h is 104 print ASCII value of m is 109 a = -80 a = 16 a = 8 a = 0
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下