运算符(3)
11.逻辑运算符真题练习
小程序
//需求1:
#include <stdio.h>
int main()
{int number;printf("请输入一个2位整数:\n");scanf_s("%d", &number);printf("%d\n", number);int ge = number % 10;int shi = number / 10 % 10;printf("%d\n", ge != 7 && shi != 7);return 0;
}
12.逻辑运算符的短路效果
13.三元运算符
代码
#include <stdio.h>
int main()
{int a = 10;int b = 20;int c = a > b ? a : b;printf("%d\n", c);printf("%d\n", a > b ? a : b);return 0;
}
#include <stdio.h>
int main()
{int a = 10;int b = 50;int c = 20;int d = a > b ? a : b;int e = c > d ? c : d;printf("%d\n", e);return 0;
}
笔记
14.逗号运算符(分隔符)
15.运算符的优先级
ps:在开发当中,不会把一行代码写得太复杂,开发追求的是代码的阅读性
在C语言中,非0都表示真,都表示成立,而0表示假,不成立