`
huiminchen
  • 浏览: 73388 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

Java运算符优先级 C++运算符优先级

 
阅读更多

Java运算符优先级
优先级   操作符   含义        关联性  用法 
----------------------------------------------------------------
1        [ ]      数组下标      左    array_name[expr] 
         .        成员选择      左    object.member 
         ( )      方法参数      左    method_name(expr_list) 
         ( )      实例构造      左    class_name(expr_list) 
         ++       后缀自增      左    lvalue++ 
         --       后缀自减      左    lvalue-- 

2        ++       前缀自增      右    ++rvalue 
         --       前缀自减      右    --lvalue 
         ~        按位取反      右    ~expr 
         !        逻辑非        右    !expr 
         +        一元加        右    +expr 
         -        一元减        右    -expr 

3        ( )      强制转换      右    (type)expr 
         new      对象实例化    右    new type() 
                                      new type(expr_list) 
                                      new type[expr] 

4        *        乘            左    expr * expr 
         /        除            左    expr / expr 
         %        求余          左    expr % expr 

5        +        加            左    expr + expr 
         -        减            左    expr - expr 
         +        字符串连接    左    strExpr + strExpr 

6        >>       有符号右移    左    expr >> distance 
         >>>      无符号右移    左    expr >>> distance 

7        <        小于          左    expr < expr 
         <=       小于等于      左    expr <= expr 
         >        大于          左    expr > expr 
         >=       大于等于      左    expr >= expr 
      instanceof  类型比较      左    ref instanceof refType 
         ==       等于          左    expr == expr 
         !=       不等于        左    expr != expr 

8        &        整数按位与    左    integralExpr & integralExpr 
         &        布尔与        左    booleanExpr & booleanExpr 

9        ^        整数按位异或  左    integralExpr ^ integralExpr 
         ^        布尔异或      左    booleanExpr ^ booleanExpr 

10       |        整数按位或    左    integralExpr | integralExpr 
         |        布尔或        左    booleanExpr | booleanExpr 

11       &&       逻辑与        左    booleanExpr && booleanExpr 

12       ||       逻辑或        左    booleanExpr || booleanExpr 

13       ? :      条件运算      右    booleanExpr ? expr : expr 

14       =        赋值          右    lvalue = expr 
         *=       乘赋值        右    lvalue *= expr 
         /=       除赋值        右    lvalue /= expr 
         %=       模赋值        右    lvalue %= expr 
         +=       加赋值        右    lvalue += expr 
         +=    字符串连接赋值   右    lvalue += expr 
         -=       减赋值        右    lvalue -= expr 
         <<=      左移赋值      右    lvalue <<= expr 
         >>=   有符号右移赋值   右    lvalue >>= expr 
         >>>=  无符号右移赋值   右    lvalue >>>= expr 
         &=    整数按位与赋值   右    lvalue &= expr 
         &=       布尔与赋值    右    lvalue &= expr 
         |=    整数按位或赋值   右    lvalue |= expr 
         |=       布尔或赋值    右    lvalue |= expr 
         ^=   整数按位异或赋值  右    lvalue ^= expr 
         ^=     布尔异或赋值    右    lvalue ^= expr 


运算符不但有优先级,还有关联性。
上表中关联性为“左”表示该表达式从左边开始进行运算;关联性为“右”表示该表达式从右边开始进行运算
转自http://topic.csdn.net/u/20110315/09/a2ab9e1a-62fa-4786-b88a-f7e6e869568c.html

C++运算符优先级
recedence	 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
16	=	 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
17	throw	 Throw operator (for exceptions)
18	,	 Comma	 Left-to-right

转自:http://www.cppblog.com/aqazero/archive/2006/06/08/8284.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics