Precedence |
Operator |
Description |
Example |
Associativity |
1 |
:: |
Scoping Operator |
Class: age = 2; |
None |
2 |
() [] -> . ++ -- |
grouping operator array access member access from a pointer member access from an object post- increment post-Decrement |
(A + B)/4; array [4] = 2; PTR-> age = 34; obj. age = 34; for (I = 0; I <10; I ++ )... for (I = 10; I> 0; I --)... |
left to right |
3 |
! ~ ++ -- - + * & (Type) Sizeof |
Logical Negation Bitwise Complement Pre-Increment Pre-Decrement Unary minus Unary plus Dereference Address Cast to a given type Return size in bytes |
If (! Done )... Flags = ~ Flags; For (I = 0; I <10; ++ I )... For (I = 10; I> 0; -- I )... Int I =-1; Int I = + 1; Data = * PTR; Address = & OBJ; Int I = (INT) floatnum; Int size = sizeof (floatnum ); |
Right to left |
4 |
-> * .* |
Member pointer Selector Member object Selector |
PTR-> * Var = 24; OBJ. * Var = 24; |
Left to right |
5 |
* / % |
Multiplication Division Modulus |
Int I = 2*4; Float F = 10/3; Int REM = 4% 3; |
Left to right |
6 |
+ - |
Addition Subtraction |
Int I = 2 + 3; Int I = 5-1; |
Left to right |
7 |
< > |
Bitwise shift left Bitwise shift right |
Int flags = 33 <1; Int flags = 33> 1; |
Left to right |
8 |
< <= > > = |
Comparison less- Comparison less-than-or-Equal- Comparison greater- Comparison geater-than-or-Equal- |
If (I <42 )... If (I <= 42 )... If (I> 42 )... If (I> = 42 )... |
Left to right |
9 |
= ! = |
Comparison equal- Comparison not-Equal- |
If (I = 42 )... If (I! = 42 )... |
Left to right |
10 |
& |
Bitwise AND |
Flags = flags & 42; |
Left to right |
11 |
^ |
Bitwise exclusive or |
Flags = flags ^ 42; |
Left to right |
12 |
| |
Bitwise random sive (normal) or |
Flags = flags | 42; |
Left to right |
13 |
&& |
Logical and |
If (conditiona & conditionb )... |
Left to right |
14 |
| |
Logical or |
If (conditiona | conditionb )... |
Left to right |
15 |
? : |
Ternary conditional (if-then-else) |
Int I = (A> B )? A: B; |
Right to left |
16 |
= + = -= * = /= % = &= ^= |=< BR ><=< BR >>= |
assignment operator increment and assign decrement and assign multiply and assign divide and assign modulo and assign bitwise AND and assign bitwise exclusive or and assign bitwise random sive (normal) or and assign bitwise shift left and assign bitwise shift right 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 |
17 |
, |
sequential evaluation operator |
for (I = 0, j = 0; I <10; I ++, J ++ )... |
left to right |