C/C++ 操作符优先级
不能光转贴,有空要熟悉之后,要写点心得。现在发现 . 的优先级确实很高。
C:
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | ++ -- |
Suffix/postfix increment and decrement | Left-to-right |
() |
Function call | ||
[] |
Array subscripting | ||
. |
Structure and union member access | ||
−> |
Structure and union member access through pointer | ||
(type){list} |
Compound literal(C99) | ||
2 | ++ -- |
Prefix increment and decrement | Right-to-left |
+ − |
Unary plus and minus | ||
! ~ |
Logical NOT and bitwise NOT | ||
(type) |
Type cast | ||
* |
Indirection (dereference) | ||
& |
Address-of | ||
sizeof |
Size-of | ||
_Alignof |
Alignment requirement(C11) | ||
3 | * / % |
Multiplication, division, and remainder | Left-to-right |
4 | + − |
Addition and subtraction | |
5 | << >> |
Bitwise left shift and right shift | |
6 | < <= |
For relational operators < and ≤ respectively | |
> >= |
For relational operators > and ≥ respectively | ||
7 | == != |
For relational = and ≠ respectively | |
8 | & |
Bitwise AND | |
9 | ^ |
Bitwise XOR (exclusive or) | |
10 | | |
Bitwise OR (inclusive or) | |
11 | && |
Logical AND | |
12 | || |
Logical OR | |
13 | ?: |
Ternary conditional | Right-to-Left |
14 | = |
Simple assignment | |
+= −= |
Assignment by sum and difference | ||
*= /= %= |
Assignment by product, quotient, and remainder | ||
<<= >>= |
Assignment by bitwise left shift and right shift | ||
&= ^= |= |
Assignment by bitwise AND, XOR, and OR | ||
15 | , |
Comma | Left-to-right |
C++:
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | :: |
Scope resolution | Left-to-right |
2 | ++ -- |
Suffix/postfix increment and decrement | |
() |
Function call | ||
[] |
Array subscripting | ||
. |
Element selection by reference | ||
−> |
Element selection through pointer | ||
3 | ++ -- |
Prefix increment and decrement | Right-to-left |
+ − |
Unary plus and minus | ||
! ~ |
Logical NOT and bitwise NOT | ||
(type) |
Type cast | ||
* |
Indirection (dereference) | ||
& |
Address-of | ||
sizeof |
Size-of | ||
new , new[] |
Dynamic memory allocation | ||
delete , delete[] |
Dynamic memory deallocation | ||
4 | .* ->* |
Pointer to member | Left-to-right |
5 | * / % |
Multiplication, division, and remainder | |
6 | + − |
Addition and subtraction | |
7 | << >> |
Bitwise left shift and right shift | |
8 | < <= |
For relational operators < and ≤ respectively | |
> >= |
For relational operators > and ≥ respectively | ||
9 | == != |
For relational = and ≠ respectively | |
10 | & |
Bitwise AND | |
11 | ^ |
Bitwise XOR (exclusive or) | |
12 | | |
Bitwise OR (inclusive or) | |
13 | && |
Logical AND | |
14 | || |
Logical OR | |
15 | ?: |
Ternary conditional | Right-to-left |
= |
Direct assignment (provided by default for C++ classes) | ||
+= −= |
Assignment by sum and difference | ||
*= /= %= |
Assignment by product, quotient, and remainder | ||
<<= >>= |
Assignment by bitwise left shift and right shift | ||
&= ^= |= |
Assignment by bitwise AND, XOR, and OR | ||
16 | throw |
Throw operator (for exceptions) | |
17 | , |
Comma | Left-to-right |
很有意思的几个举例:
http://www.cnblogs.com/maowang1991/archive/2012/12/07/2807086.html
C/C++ 操作符优先级的更多相关文章
- C语言操作符优先级
C语言操作符优先级 优先级 运算符 含 义 要求运算 对象的个数 结合方向 1 () [] -> . 圆括号 下标运算符 指向结构体成员运算符 结构体成员运算符 自左至右 2 ! 逻辑非运 ...
- 被C语言操作符优先级坑了
今天有一个枚举的题目的代码是这样的: 重点在于maxXor这个函数的实现,枚举两个数字,其中maxr保存了最大值的 i 异或 j , 可是这个程序执行结果大大出乎意外-_-. 然后就把 i 异或 j ...
- C++操作符优先级带来的错误
在刷LeetCode题目:190. 颠倒二进制位:颠倒给定的 32 位无符号整数的二进制位时,可以利用左移和右移操作符来实现数字翻转: 错误解法: class Solution { public: u ...
- JS规则 保持先后顺序(操作符优先级)操作符之间的优先级(高到低): 算术操作符 → 比较操作符 → 逻辑操作符 → "="赋值符号
保持先后顺序(操作符优先级) 我们都知道,除法.乘法等操作符的优先级比加法和减法高,例如: var numa=3; var numb=6 jq= numa + 30 / 2 - numb * 3; / ...
- c++ 操作符优先级
优先级 操作符 描述 例子 结合性 1 ()[]->.::++-- 调节优先级的括号操作符数组下标访问操作符通过指向对象的指针访问成员的操作符通过对象本身访问成员的操作符作用域操作符后置自增操作 ...
- C++ 语言操作符的优先级
cppreference.com -> C++ 操作符优先级 C++ 操作符优先级 优先级 操作符 1 () [] -> . :: ! ~ ++ ...
- JavaScript操作符(=?,)优先级
JavaScript操作符优先级: 关于最后3个运算符的优先级比较,下面通过一个实例来具体说明: var a,b,c; a = 3,4,5; b = a--,--a,a; c = a ? b++ : ...
- Python-5 数据类型、操作符
#1 数值类型: 整型int.浮点型float(科学记数法 e 或 E).布尔型bool #2 字符串: 与整型.浮点型转化:int()--截断处理 float() str() #3 获取数据类型: ...
- java基础-操作符
浏览以下内容前,请点击并阅读 声明 定义:操作符是一种能够对一个,两个或三个操作对象执行特定的操作,并返回一个结果的特定符号. java中操作符的种类和优先级如下表所示,除了赋值运算,所有二元操作符运 ...
随机推荐
- OMS数据库调整1
一.增加2T存储空间 1. 对磁盘进行分区并格式化 [root@oms-db01 ~]# fdisk -l Disk /dev/sda: 322.1 GB, 322122547200 bytes 2 ...
- SoapUI offen used scripts
[ Groovy Step ] //get properties from testCase, testSuite and project in groovy step def testCasePro ...
- BZOJ 2300 [HAOI2011]防线修建 ——计算几何
只需要倒着插入,然后维护一个凸包就可以了. 可以用来学习set的用法 #include <map> #include <set> #include <cmath> ...
- BZOJ 2005 [Noi2010]能量采集 ——Dirichlet积
[题目分析] 卷积一卷. 然后分块去一段一段的求. O(n)即可. [代码] #include <cstdio> #include <cstring> #include < ...
- spring工作机制及为什么要用?
spring工作机制及为什么要用?1.spring mvc请所有的请求都提交给DispatcherServlet,它会委托应用系统的其他模块负责对请求进行真正的处理工作.2.DispatcherSer ...
- 作诗(bzoj 2821)
Description 神犇SJY虐完HEOI之后给傻×LYD出了一题:SHY是T国的公主,平时的一大爱好是作诗.由于时间紧迫,SHY作完诗 之后还要虐OI,于是SHY找来一篇长度为N的文章,阅读M次 ...
- eclipse 搭建ruby环境
第一步:获取RDT,http://sourceforge.net/projects/rubyeclipse/files/ 解压该文件,获得features和plugins两个文件夹,将这两个文件夹分别 ...
- POJ 2411 状压dp
F - Mondriaan's Dream Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I6 ...
- 【笔记】Linux内核中的循环缓冲区
1. 有关ring buffer的理解 1) ring buffer位首尾相接的buffer,即类似生活中的圆形跑道: 2) 空闲空间+数据空间=ring buffer大小 3) ring bu ...
- 关于整合spring+mybatis 第二种方式
和第一种方式一样的步骤,不过bean.xml中有些许差异 <!-- 配置sqlSessionFactory --> <bean id="sqlSessionFactory& ...