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


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

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

转自:[url]http://www.cppblog.com/aqazero/archive/2006/06/08/8284.html[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值