C++算符优先级列表

最近进行了几个面试,在算符优先级这个问题上难倒了几次,真是悲催啊,好久没用C的悲剧。

特此复习一下:

Precedence Operator Description Overloadable Associativity
1 :: scope resolution no left to right
2 () function call yes left to right
[] array access yes
-> member access yes
. no
++  -- postfix yes
dynamic_cast  static_cast  reinterpret_cast  const_cast type conversion no
typeid Get type information no
3 !  not logical negation yes right to left
~  compl bitwise negation (complement) yes
++  -- prefix yes
+  - unary sign operations yes
*  & indirection and reference yes
sizeof Size (of the type) of the operand in bytes no
new  new[]  delete  delete[] dynamic memory management yes
(type) Cast to a given type yes
4 ->* member pointer selector yes left to right
.* member object selector no
5 *  /  % arithmetic operations yes left to right
6 +  -
7 <<  >> shift operations yes left to right
8 <  <=  >  >= relational operations yes left to right
9 ==  != not_eq
10 &  bitand bitwise AND yes left to right
11 ^  xor bitwise XOR yes left to right
12 |  bitor bitwise OR yes left to right
13 &&  and logical AND yes left to right
14 ||  or logical OR yes left to right
15 ?: Ternary conditional (if-then-else) no right to left
16 =  +=  -=  *=  /=  %=  &=  ^= |= <<= >>= assignment yes right to left
17 , Sequential evaluation operator yes left to right
posted @ 2011-03-26 20:40  Zek  阅读(178)  评论(0编辑  收藏  举报