C C++ Operator precedence

3396 ワード

C C++ Operator precedence
Precedence
Operator
Description
Associativity
1 highest ::
Scope resolution (C++ only)
None
2 ++
Suffix increment
Left-to-right --
Suffix decrement ()
Function call []
Array subscripting .
Element selection by reference ->
Element selection through pointer typeid()
Run-time type information (C++ only) (see typeid) const_cast
Type cast (C++ only) (see const_cast) dynamic_cast
Type cast (C++ only) (see dynamic_cast) reinterpret_cast
Type cast (C++ only) (see reinterpret_cast) static_cast
Type cast (C++ only) (see static_cast)
3 ++
Prefix increment
Right-to-left --
Prefix decrement +
Unary plus -
Unary minus !
Logical NOT ~
Bitwise NOT (One's Complement) (type)
Type cast *
Indirection (dereference) &
Address-of sizeof
Size-of new , new[]
Dynamic memory allocation (C++ only) delete , delete[]
Dynamic memory deallocation (C++ only)
4 .*
Pointer to member (C++ only)
Left-to-right ->*
Pointer to member (C++ only)
5 *
Multiplication
Left-to-right /
Division %
Modulo (remainder)
6 +
Addition
Left-to-right -
Subtraction
7 <<
Bitwise left shift
Left-to-right >>
Bitwise right shift
8 <
Less than
Left-to-right <=
Less than or equal to >
Greater than >=
Greater than or equal to
9 ==
Equal to
Left-to-right !=
Not equal to
10 &
Bitwise AND
Left-to-right
11 ^
Bitwise XOR (exclusive or)
Left-to-right
12 |
Bitwise OR (inclusive or)
Left-to-right
13 &&
Logical AND
Left-to-right
14 ||
Logical OR
Left-to-right
15 ?:
Ternary conditional (see ?:)
Right-to-left
16 =
Direct assignment
Right-to-left +=
Assignment by sum -=
Assignment by difference *=
Assignment by product /=
Assignment by quotient %=
Assignment by remainder <<=
Assignment by bitwise left shift >>=
Assignment by bitwise right shift &=
Assignment by bitwise AND ^=
Assignment by bitwise XOR |=
Assignment by bitwise OR
17 throw
Throw operator (exceptions throwing, C++ only)
Right-to-left
18 lowest ,
Comma
Left-to-right
reference url: http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B