当前位置:网站首页>c语言里怎么设立优先级,细说C语言优先级
c语言里怎么设立优先级,细说C语言优先级
2022-07-02 18:37:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
0. 为什么要掌握优先级
想想这两个问题:
a. 读别人的代码,遇到优先级问题看不懂,怎么办?
b. 一堆的括号,美观吗?
本想贴一张画来装饰墙壁,却用了一堆纸来固定!
有人说代码写多了,自然就会了。这个是很宽泛的说法。看你写的代码的水准,有些东西可能你一直
都接触不到,何谈熟练。有些东西一定要梳理,总结。
1. 优先级
1.1 优先级图表
优先级最高者不是真正意义上的运算符,包括:数组下标,函数调用,结构体成员选择符。
单目运算符的优先级次之。(! ~ ++ — – (type) * & sizeof)
然后是双目运算符。双目运算符里, 算数运算符(* / % + -)优先级最高, 移位(<< >>)次之, 关系
运算符(< <= > >= != ==)再次之, 接着是位运算符(& ^ | ),逻辑运算符(&& ||) 条件运算符(?: 三目),
赋值运算符(= …)。
任何一个逻辑运算符的优先级低于任何一个关系运算符。
移位运算符的优先级比算数运算符要低,但是比关系运算符要高。
1.2 运算符实例
a. while (c = getc(in) != EOF)
putc(c, out)
循环的意思是复制一个文件到另一个文件。但是由于!=的优先级比赋值运算符的优先级高,所以c
被赋予了getc()的返回值与EOF比较后的布尔值,结果向out中写入了一堆1.
1.3 优先级顺口溜
醋坛酸味灌
味落跳福豆
共44个运算符
醋-初等,4个: ( ) [ ] -> 指向结构体成员 . 结构体成员
坛-单目,9个: ! ~ ++ — -负号 (类型) *指针 &取地址 sizeof长度
酸-算术,5个: * / % + -减
味-位移,2个: << >>
灌-关系,6个: < <= > >= == 等于 != 不等于
味-位逻,3个: & 按位与 ^ 按位异或 | 按位或
落-逻辑,2个: && 逻辑与 || 逻辑或
跳-条件,1个,三目: ? :
福-赋值,11个: = += -= *= /= %= >>= <<= &= ^= |=
豆-逗号,1个: ,
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148556.html原文链接:https://javaforall.cn
边栏推荐
- 安装单机redis详细教程
- Golang:[]byte to string
- 452-strcpy、strcat、strcmp、strstr、strchr的实现
- 为什么要做企业固定资产管理系统,企业如何加强固定资产管理
- Is there any security guarantee for the ranking of stock and securities companies
- Digital scroll strip animation
- 教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
- Getting started with typescript
- IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
- Golang并发编程——goroutine、channel、sync
猜你喜欢
Quanzhi A33 uses mainline u-boot
Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
End to end object detection with transformers (Detr) paper reading and understanding
《重构:改善既有代码的设计》读书笔记(下)
According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5
Markdown基础语法
随机推荐
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
A4988驱动步进电机「建议收藏」
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
Mobile robot path planning: artificial potential field method [easy to understand]
Golang并发编程——goroutine、channel、sync
AcWing 1135. 新年好 题解(最短路+搜索)
多态的理解以及作用
使用xml文件打印mybaties-log插件的方式
AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
Fastdfs installation
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
NPOI导出Excel2007
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
Digital scroll strip animation
Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
What is the MySQL backup suffix_ MySQL backup restore
AcWing 1127. 香甜的黄油 题解(最短路—spfa)