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中操作符的种类和优先级如下表所示,除了赋值运算,所有二元操作符运 ...
随机推荐
- HDU——2612Find a way(多起点多终点BFS)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- [luoguP2325] [SCOI2005]王室联邦(树分块乱搞)
传送门 想了半小时,没什么思路.. 看了题解,是个叫做树分块的奇奇怪怪的操作.. 题解 树分块的研究 #include <cstdio> #include <cstring> ...
- 算法复习——bitset(bzoj3687简单题)
题目: Description 小呆开始研究集合论了,他提出了关于一个数集四个问题:1.子集的异或和的算术和.2.子集的异或和的异或和.3.子集的算术和的算术和.4.子集的算术和的异或和. 目前 ...
- 648. Replace Words
Problem statement In English, we have a concept called root, which can be followed by some other wor ...
- Radio Transmission(bzoj 1355)
Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,1 < L ≤ 1, ...
- 【BZOJ1412】狼和羊的故事(最小割)
题意:将一个由0,1,2构成的矩阵里的1与2全部分割最少需要选取多少条边 n,m<=100 思路:裸的最小割模型 相邻的格子连容量为1的边(其实可以少连很多遍,1与1,2与2之间的边是没有意义的 ...
- 转 DOS 8.3 文件名命名规则
http://www.360doc.com/content/10/0813/14/73007_45757514.shtml DOS 8.3 文件名命名规则 经常看到命令行或者其它软件在显示目录的时候出 ...
- ScrollPic.js——图片左右滚动插件
自己在做项目的时候刚好遇到了图片做左右滚动的项目,发现ScrollPic.js这个插件还是很好用的,一般的浏览器都支持,也可以做成bootstrap样式: 首先需要下载ScrollPic.js这个插件 ...
- js-判断当前页面是否在微信浏览器中打开
方案一:推荐 var ua = navigator.userAgent.toLowerCase(); var isWinxin = ua.indexOf('micromessenger') != -1 ...
- weex splash页面
1.Splash.vue <!-- splash页面 --> <template> <div class="wrap" @focus="ro ...