Priority Level |
operator |
Description |
Example |
combination of |
1 |
() [] -> . :: ++ -- |
Bracket operator for adjusting precedence Array Subscript access operator To access a member's operator by pointing to an object's pointer To access a member's operator through the object itself Scope operator Post self-increment operator Post Self subtraction operator |
(A + B)/4; ARRAY[4] = 2; Ptr->age = 34; Obj.age = 34; Class::age = 2; for (i = 0; i < i++) ... for (i = i > 0; i--) ... |
From left to right |
2 |
! ~ ++ -- - + * & (type) sizeof |
Logical fetch inverse operator Bitwise reverse (by bit to fill) Forward self-increment operator Forward self-subtraction operator Unary take negative operator Unary take positive operator Solution Reference operator Take address operator Type conversion operators Returns the number of bytes used by the object operator |
if (!done) ... Flags = ~flags; for (i = 0; i < ++i) ... for (i = 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 |
->* .* |
To access a member's operator on the pointer by a pointer to a member To access a member's operator on an object by pointing to a pointer to a member |
Ptr->*var = 24; Obj.*var = 24; |
From left to right |
4 |
* / % |
Multiplication operator Division operator Take the remainder operator |
int i = 2 * 4; float F = 10/3; int rem = 4% 3; |
From left to right |
5 |
+ - |
Addition operator Subtraction operator |
int i = 2 + 3; int i = 5-1; |
From left to right |
6 |
<< >> |
Bitwise left-shift operator Bitwise right-shift operator |
int flags = << 1; int flags = >> 1; |
From left to right |
7 |
< <= > >= |
Less than comparison operator Less than or equal to comparison operator Greater than comparison operator Greater than or equal to comparison operator |
if (I < 42) ... if (i <= 42) ... if (i > 42) ... if (i >= 42) ... |
From 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 |
= += -= *= /= %= &= ^= |= <<= >>= |
Assignment operator Compound assignment Operator (addition) Compound assignment operator (subtraction) Compound assignment operator (multiplication) Compound assignment Operator (division) Compound assignment operator (remainder) Compound assignment operators (bitwise AND) Compound assignment operator (bitwise XOR OR) Compound assignment operator (bitwise OR) Compound assignment operator (move left by bit) Compound assignment operator (move right by bit) |
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 |