当前位置:网站首页>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
边栏推荐
- AcWing 343. 排序 题解(floyd性质实现传递闭包)
- 450-深信服面经1
- AcWing 1131. 拯救大兵瑞恩 题解(最短路)
- 452-strcpy、strcat、strcmp、strstr、strchr的实现
- PHP非对称加密方法私钥及公钥加密解密的方法
- 2022 compilation principle final examination recall Edition
- 函数高阶-柯里化实现
- Talk about the design of red envelope activities in e-commerce system
- Use cheat engine to modify money, life and stars in Kingdom rush
- Yolov3 trains its own data set to generate train txt
猜你喜欢
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
Yunna | why use the fixed asset management system and how to enable it
教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5
搭建哨兵模式reids、redis从节点脱离哨兵集群
Markdown基础语法
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
Markdown basic grammar
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
PHP-Parser羽毛球预约小程序开发require线上系统
Codeworks 5 questions per day (1700 average) - day 4
随机推荐
Chapter 7 - class foundation
Use cheat engine to modify money, life and stars in Kingdom rush
mybatiesHelperPro工具必须的可以生成到对应项目文件夹下
Develop fixed asset management system, what voice is used to develop fixed asset management system
Refactoring: improving the design of existing code (Part 1)
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
Notes de lecture sur le code propre
Fastdfs installation
虚拟机初始化脚本, 虚拟机相互免秘钥
452-strcpy、strcat、strcmp、strstr、strchr的实现
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
NPOI导出Excel2007
4274. Suffix expression - binary expression tree
Gmapping code analysis [easy to understand]
AcWing 1127. 香甜的黄油 题解(最短路—spfa)
AcWing 1137. Select the best line solution (the shortest circuit)
Mobile robot path planning: artificial potential field method [easy to understand]
AcWing 181. 回转游戏 题解(搜索—IDA*搜索)
Bubble sort array
AcWing 1137. 选择最佳线路 题解(最短路)