-
Notifications
You must be signed in to change notification settings - Fork 0
Operators
Shachar Shemesh edited this page Mar 16, 2019
·
4 revisions
| Precedence | Operator | Description | Associativity | Comments |
|---|---|---|---|---|
| 1 (highest) |
:: |
Scope resolution | None | |
| 2 | ++ |
Postfix increment | Left-to-right | |
-- |
Postfix decrement | |||
() |
Function call | |||
[] |
Array/Slice subscripting | |||
. |
Struct member selection (lvalue) | |||
-> |
Struct member selection (pointer) | |||
cast!type |
Static cast | |||
const_cast!type |
CV removal cast | |||
reinterpret_cast!type |
||||
| 3 | ++ |
Prefix increment | Right-to-left | |
-- |
Prefix decrement | |||
+ |
Unary plus | |||
- |
Unary minus | |||
~ |
Bitwise NOT (One's complement) | |||
! |
Logical NOT | |||
(type) |
Safe cast (explicit implicit cast) | Should probably have lower priority | ||
* |
Pointer dereference | |||
& |
Address-of | |||
| 4 | Reserved | |||
| 5 | * |
Multiplication | Left-to-right | |
/ |
Division | |||
% |
Modulo (remainder) | |||
& |
Bitwise AND | Higher priority than C++ | ||
| 6 | + |
Addition | Left-to-right | |
- |
Subtraction | |||
| |
Bitwise OR | Higher priority than C++ | ||
^ |
Bitwise XOR | Higher priority than C++ | ||
| 7 | << |
Left shift | Left-to-right | |
>> |
Right shift | |||
>>> |
Right shift (unsigned) | Consider whether needed | ||
| 8 | < |
Less than | Left-to-right | |
<= |
Less than or equals | |||
> |
Greater than | |||
>= |
Greater than or equals | |||
| 9 | == |
Equals | Left-to-right | |
!= |
Not equals | |||
| 10 | && |
Logical AND | Left-to-right | |
| 11 | || |
Logical OR | Left-to-right | |
| 12 | = |
Assignement | Right-to-left | |
+= |
Additive assignment | |||
-= |
Subtractive assignment | |||
*= |
Multiplicative assignment | |||
/= |
Division assignment | |||
%= |
Modulo assignment | |||
<<= |
Left shift assignment | |||
>>= |
Right shift assignment | |||
>>>= |
Logical right shift assignment | Consider whether needed | ||
&= |
Bitwise AND assignment | |||
^= |
Bitwise XOS assignment | |||
|= |
Bitwise OR assignment |
- Practical has no conditional operator (
?:). Instead,ifcan be used as an expression to the same effect. - Practical has no comma operator (
,). Aside from being a horrible abomination, a compound expression can serve the precise same purpose.