当前位置:网站首页>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
边栏推荐
- SIFT特征点提取「建议收藏」
- 安装单机redis详细教程
- Golang:[]byte to string
- GMapping代码解析[通俗易懂]
- Bubble sort array
- LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
- Markdown basic grammar
- 教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5
- Processing strategy of message queue message loss and repeated message sending
- Advanced performance test series "24. Execute SQL script through JDBC"
猜你喜欢
PHP-Parser羽毛球预约小程序开发require线上系统
codeforces每日5题(均1700)-第四天
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
Processing strategy of message queue message loss and repeated message sending
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
冒泡排序数组
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
Markdown basic grammar
Excel finds the same value in a column, deletes the row or replaces it with a blank value
随机推荐
Thread application instance
注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
冒泡排序数组
AcWing 1137. Select the best line solution (the shortest circuit)
AcWing 1128. 信使 题解(最短路—Floyd)
Markdown基础语法
使用xml文件打印mybaties-log插件的方式
数据降维——因子分析
PHP-Parser羽毛球预约小程序开发require线上系统
《代码整洁之道》读书笔记
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捷径
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
多态的理解以及作用
搭建主从模式集群redis
Emmet basic syntax
Which video recording software is better for the computer
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
程序猿入门攻略(十二)——数据的存储
云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统