不能光转贴,有空要熟悉之后,要写点心得。现在发现 . 的优先级确实很高。

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
newnew[] Dynamic memory allocation
deletedelete[] 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++ 操作符优先级的更多相关文章

  1. C语言操作符优先级

    C语言操作符优先级 优先级 运算符 含    义 要求运算 对象的个数 结合方向 1 () [] -> . 圆括号 下标运算符 指向结构体成员运算符 结构体成员运算符 自左至右 2 ! 逻辑非运 ...

  2. 被C语言操作符优先级坑了

    今天有一个枚举的题目的代码是这样的: 重点在于maxXor这个函数的实现,枚举两个数字,其中maxr保存了最大值的 i 异或 j , 可是这个程序执行结果大大出乎意外-_-. 然后就把 i 异或 j ...

  3. C++操作符优先级带来的错误

    在刷LeetCode题目:190. 颠倒二进制位:颠倒给定的 32 位无符号整数的二进制位时,可以利用左移和右移操作符来实现数字翻转: 错误解法: class Solution { public: u ...

  4. JS规则 保持先后顺序(操作符优先级)操作符之间的优先级(高到低): 算术操作符 → 比较操作符 → 逻辑操作符 → "="赋值符号

    保持先后顺序(操作符优先级) 我们都知道,除法.乘法等操作符的优先级比加法和减法高,例如: var numa=3; var numb=6 jq= numa + 30 / 2 - numb * 3; / ...

  5. c++ 操作符优先级

    优先级 操作符 描述 例子 结合性 1 ()[]->.::++-- 调节优先级的括号操作符数组下标访问操作符通过指向对象的指针访问成员的操作符通过对象本身访问成员的操作符作用域操作符后置自增操作 ...

  6. C++ 语言操作符的优先级

    cppreference.com -> C++ 操作符优先级 C++ 操作符优先级        优先级     操作符 1 () [] -> .   ::         ! ~ ++ ...

  7. JavaScript操作符(=?,)优先级

    JavaScript操作符优先级: 关于最后3个运算符的优先级比较,下面通过一个实例来具体说明: var a,b,c; a = 3,4,5; b = a--,--a,a; c = a ? b++ : ...

  8. Python-5 数据类型、操作符

    #1 数值类型: 整型int.浮点型float(科学记数法 e 或 E).布尔型bool #2 字符串: 与整型.浮点型转化:int()--截断处理 float() str() #3 获取数据类型: ...

  9. java基础-操作符

    浏览以下内容前,请点击并阅读 声明 定义:操作符是一种能够对一个,两个或三个操作对象执行特定的操作,并返回一个结果的特定符号. java中操作符的种类和优先级如下表所示,除了赋值运算,所有二元操作符运 ...

随机推荐

  1. Unity3D for iOS初级教程:Part 2/3

    转自Unity3D for iOS 这篇文章还可以在这里找到 英语 Learn how to use Unity to make a simple 3D iOS game! 这篇教材是来自教程团队成员 ...

  2. 【Luogu】P2704炮兵阵地(状压DP)

    题目链接 话说还真没见过能影响两行的状压.想了半天想出来f数组再多一维就能表示,但是没想到怎么才能不爆空间…… 也是从这道题里学到的一个妙招. 可以把合法状态存到一个数组里,然后用数组下标来映射状态. ...

  3. BZOJ 2246 [SDOI2011]迷宫探险 ——动态规划

    概率DP 记忆化搜索即可,垃圾数据,就是过不掉最后一组 只好打表 #include <cstdio> #include <cstring> #include <iostr ...

  4. 【bzoj1193】[HNOI2006]马步距离

    [HNOI2006]马步距离 Description Input 只包含4个整数,它们彼此用空格隔开,分别为xp,yp,xs,ys.并且它们的都小于10000000. Output 含一个整数,表示从 ...

  5. Chapter 4-5

    1.切片对象  sequence[起始索引:结束索引:步进值] 对象身份的比较 is /is not 2.eval()参数是一个字符串, 可以把这个字符串当成表达式来求值. >>>x ...

  6. 【笔记】Linux内核中的循环缓冲区

    1. 有关ring buffer的理解 1)  ring buffer位首尾相接的buffer,即类似生活中的圆形跑道: 2)  空闲空间+数据空间=ring buffer大小 3)  ring bu ...

  7. 清除svn检出导致的所有文件的问号

    问题:将svn项目检出到桌面后,桌面的图标都有问号了,怎么消除这一大堆问号? 解决方案:(1)新建一个a.txt文件,把这行代码复制进去for /r . %%a in (.) do @if exist ...

  8. windows软件配置

    1 安装jdk 配置环境变量 新建JAVA_HOME:D:\Program Files\Java\jdk1.8.0_151 新建JRE_HOME:D:\Program Files\Java\jre1. ...

  9. BZOJ3674 可持久化并査集

    @(BZOJ)[可持久化并査集] Description n个集合 m个操作 操作: 1 a b 合并a,b所在集合 2 k 回到第k次操作之后的状态(查询算作操作) 3 a b 询问a,b是否属于同 ...

  10. JavaScript对列表节点的操作:删除指定节点、删除最后一个节点、删除第一个节点、删除所有节点、增加节点

    使用菜鸟的运行环境直接测试:http://www.runoob.com/try/try.php?filename=tryjs_events <!DOCTYPE html> <html ...