Precedence |
Operator |
Description |
Example |
associativity |
1 |
() [] -> . :: ++ -- |
Grouping operator Array Access member access from a pointer member access from an object Scoping operator Post-increment Post-decrement |
(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--) ... |
Left to right |
2 |
! ~ + + -- - + * / (type) sizeof |
logical negation Bitwise complement Pre-increment Pre-decrement Unary minus Unary plus dereference Address of Cast to a given type return size in bytes |
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); |
right to left |
3 |
->* .* |
Member Pointer selector Member Pointer selector |
Ptr->*var = 24; Obj.*var = 24; |
Left to right |
4 |
* / % |
Multiplication Division Modulus |
int i = 2 * 4; float F = 10/3; int rem = 4% 3; |
Left to right |
5 |
+ - |
Addition Subtraction |
int i = 2 + 3; int i = 5-1; |
Left to right |
6 |
<< >> |
Bitwise SHIFT LEFT Bitwise SHIFT Right |
int flags = << 1; int flags = >> 1; |
Left to right |
7 |
< <= > >= |
Comparison Less-than Comparison less-than-or-equal-to Comparison Greater-than Comparison geater-than-or-equal-to |
if (I < 42) ... if (i <= 42) ... if (i > 42) ... if (i >= 42) ... |
Left to right |
8 |
== != |
Comparison equal-to Comparison not-equal-to |
if (i = = 42) ... if (i!= 42) ... |
Left to right |
9 |
& |
Bitwise AND |
Flags = flags & 42; |
Left to right |
10 |
^ |
Bitwise EXCLUSIVE OR |
Flags = flags ^ 42; |
Left to right |
11 |
| |
Bitwise inclusive (normal) OR |
Flags = Flags | 42; |
Left to right |
12 |
&& |
Logical and |
if (Conditiona && conditionb) ... |
Left to right |
13 |
|| |
Logical OR |
if (Conditiona | | conditionb) ... |
Left to right |
14 |
|
ternary Conditi Onal (if-then-else) |
int i = (a > B)? a:b; |
right to left |
15 |
= + = -= *= /= % = &= ^= |= <<= >>= |
assignment operator Increment and assign Decrement and assign Multiply and assign Divide and assign modulo and assign bitwise AND and assign Bitwis E exclusive OR and assign Bitwise inclusive (normal) or and assign bitwise shift LEFT and assign bitwise shift RI Ght and assign |
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; |
right to left |
16 |
|
sequential Evaluation operator |
for (i = 0, j = 0; I < i++, j + +) ... |
left to right |