当前位置:网站首页>MOOC翁恺C语言 第四周:进一步的判断与循环:1.逻辑类型与运算2.级联和嵌套的判断
MOOC翁恺C语言 第四周:进一步的判断与循环:1.逻辑类型与运算2.级联和嵌套的判断
2022-07-28 05:28:00 【W.934】
一.逻辑类型与运算
1.逻辑运算:逻辑运算是对逻辑量进行的运算,结果只有0或1.
系运算或逻辑运算的结果。


逻辑运算是自左向右进行的。
不要把赋值,包括复合赋值组合进表达式。
2.条件运算符
count=(count>20)?count-10:count+10;
? 前面的是 条件
? 后面的是 条件满足后的值
: 后面的是 条件不满足后的值
_相当于
if(count>20)
count=count-10;
else
count=count+10;(编程语言早期遗留下的东西)
3.逗号运算符
逗号用来连接两个表达式,并以其右边的表达式的值作为它运算的结果。
eg: i=(3+4,5+6) 结果为11,即 i=(3+4,5+6)
逗号的优先级是所有的运算符中最低的,所以它两边的表达式会先计算;逗号的组合关系是自左向右,所以左边的表达式会先计算,而右边的表达式的值就留下来作为逗号运算的结果。
eg:i=3+4,5+6 结果为7,即i=3+4,5+6
逗号表达式主要是在for当中使用(目前只有这一个用处):当想在for中放多个计算时:
for(i=0,j=10;i<j;i++,j--)
二.级联和嵌套的判断
1.嵌套的if-else
else总和最近的那个if匹配,缩进格式不能暗示if else的匹配。
建议:在if或else后面总是用{},即使只有一条语句的时候。
2. 级联的if-else
if(exp1)
st1;
else if(exp2)
st2;
else
st3;
边栏推荐
- 思寒漫谈测试人职业发展
- cocos2d-x 学习笔记——瓦片地图TiledMap
- HDU-5805-NanoApe Loves Sequence(思维题)
- Custom component -- data listener
- Ubuntu18.04+Centos7配置redis主从【学习笔记】
- KVM hot migration
- Hdu-2036-reform spring breeze blowing all over the ground (polygon area template)
- What kind of air conduction Bluetooth headset with good configuration is recommended
- 测试面试题集锦(五)| 自动化测试与性能测试篇(附答案)
- Si Han talks about the professional development of testers
猜你喜欢

File operation in C language

LNMP搭建过程详解

1、 PXE overview and installation

技术分享 | 接口测试常用代理工具

Custom components -- styles

2022 Tanabata gift recommendation! Nice, cheap and practical gift recommendation

Qgraphicsview promoted to qchartview

技术分享 | 服务端接口自动化测试, Requests 库的这些功能你了解吗?

Which is the best air conduction Bluetooth headset? Air conduction Bluetooth headset ranking

Which brand of air conduction earphones is better? These four should not be missed
随机推荐
MySQL主主
Common models in software development
Hdu-5805-nanoape loves sequence (thinking questions)
Esxi community network card driver updated again
What is the most practical gift for Tanabata? A gift that will never go wrong is worth buying
Forward and backward slash notes
Technology sharing | do you know the functions of the server interface automated testing and requests library?
Qgraphicsview promoted to qchartview
Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
HDU-5783 Divide the Sequence(贪心水题)
Repair the faulty sector
测试面试题集锦(三)| 计算机网络和数据库篇(附答案)
Tcp/ip five layer model
shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置
Build php7 private warehouse
DNS域名解析服务
Network - data link layer
On cookies and session
Servlet
技术分享 | 接口测试常用代理工具