Priority Level |
operator |
Description |
Example |
Binding Nature |
1 |
() [] - . :: ++ -- |
The parentheses operator that adjusts the precedence Array Subscript access operator To access a member's operator by pointing to the object's pointer Operator that accesses members through the object itself Scope operator Post increment operator Post-decrement operator |
(A + B)/4; ARRAY[4] = 2; Ptr->age = 34; Obj.age = 34; Class::age = 2; for (i = 0; i <; i++) ... for (i = ten; i > 0; i--) ... |
From left to right |
2 |
! ~ ++ -- - + * & (type) sizeof |
logical inverse operator bitwise inverse pre-decrement operator unary minus operator unary take positive operator Span style= "FONT-SIZE:18PX;" > dereference operator fetch address operator Returns the number of bytes occupied by the object operator |
if (!done) ... Flags = ~flags; for (i = 0; i <; ++i) ... for (i = ten; i > 0; i.) ... int i =-1; int i = +1; data = *ptr; Address = &obj; int i = (int) floatnum; int size = sizeof (floatnum); |
From right to left |
3 |
->* .* |
|
obj.*var =; |
left-to-right |
4 |
* / % |
multiplication operator division operator Span style= "FONT-SIZE:18PX;" > Take the remainder operator |
int i = 2 * 4; float f = 10/3; int rem = 4 3; |
left-to-right |
5 |
+ - |
subtraction operator |
int i = 2 + 3; int i = 5-1; |
left-to-right |
6 |
<< bitwise left SHIFT operator bitwise right SHIFT operator |
int flags = << 1; int flags = >> 1; |
left-to-right |
7 |
< > Span style= "FONT-SIZE:18PX;" >>= |
less than comparison operator is less than or equal to the comparison operator greater than the comparison operator |
if (i <) ... if (i <=) ... if (i >) ... if (i >=) ... |
left-to-right |
8 |
== != |
equals comparison operator Not equal to comparison operator |
if (i = = 42) ... if (i! = 42) ... |
From left to right |
9 |
& |
Bitwise AND operator |
Flags = flags & 42; |
From left to right |
10 |
^ |
Bitwise XOR OR operator |
Flags = flags ^ 42; |
From left to right |
11 |
| |
Bitwise OR operator |
Flags = Flags | 42; |
From left to right |
12 |
&& |
Logic and operators |
if (Conditiona && conditionb) ... |
From left to right |
13 |
|| |
Logical OR operator |
if (Conditiona | | conditionb) ... |
From left to right |
14 |
? : |
Ternary conditional operator |
int i = (a > B)? A:B; |
From right to left |
15 |
= += -= *= /= %= &= ^= Span style= "FONT-SIZE:18PX;" >|= <<= >>= |
compound assignment operator (subtraction) compound assignment operator (division) compound assignment operator (bitwise AND) compound assignment operator (bitwise OR) compound assignment operator (bitwise right SHIFT) |
int a = b; A + = 3; B-= 4; A *= 5; A/= 2; A%= 3; Flags &= new_flags; Flags ^= new_flags; Flags |= new_flags; Flags <<= 2; Flags >>= 2; |
From right to left |
16 |
, |
Comma operator |
for (i = 0, j = 0; i <; i++, J + +) ... |
From left to right |
C + + operator precedence