List of C operators with their symbol, syntax and precedence.
Symbol | Syntax | Name | Precedence |
---|---|---|---|
[] | [x] | brackets | 1 |
() | (x) | parenthesis | 1 |
-> |
p->member |
structure member (from pointer) | 1 |
. | x.member | structure member | 1 |
++ | ++x | prefix increment | 2 |
-- | --x | prefix decrement | 2 |
++ | x++ | postfix increment | 2 |
-- | x-- | postfix decrement | 2 |
& | &x | variable address | 2 |
* | *p | pointer indirection | 2 |
sizeof() | sizeof(x) | size of variable in bytes | 2 |
(type) | (type)x | type cast | 2 |
~ | ~x | bitwise NOT | 2 |
! | !x | logical NOT | 2 |
+ | +x | unary plus | 2 |
- | -x | unary minus | 2 |
* | x*y | multiplication | 3 |
/ | x/y | division | 3 |
% | x%y | modulus (integer) | 3 |
+ | x+y | addition | 4 |
- | x-y | subtraction | 4 |
<< | x<<y | left shift | 5 |
>> | x>>y | right shift | 5 |
> | x>y | greater than | 6 |
>= | x>=y | greater than or equal | 6 |
< | x<y | smaller than | 6 |
<= | x<=y | smaller than or equal | 6 |
== | x==y | comparison - equal to | 7 |
!= | x!=y | comparison - not equal to | 7 |
& | x&y | bitwise AND | 8 |
^ | x^y | bitwise XOR | 9 |
| | x|y | bitwise OR | 10 |
&& | x&&y | logical AND | 11 |
|| | x||y | logical OR | 12 |
?: | C ? T : F | Conditional expression | 13 |
= | x=y | assignment operator | 14 |
+= | x+=y | addition and assignment | 14 |
-= | x-=y | subtraction and assignment | 14 |
*= | x*=y | multiplication and assignment | 14 |
/= | x/=y | division and assignment | 14 |
%= | x%=y | modulus and assignment | 14 |
&= | x&=y | bitwise AND and assignment | 14 |
|= | x|=y | bitwise OR and assignment | 14 |
^= | x^=y | bitwise XOR and assignment | 14 |
>>= | x>>=y | right shift and assignment | 14 |
<<= | x<<=y | left shift and assignment | 14 |
, | x,y | Comma - expressions separator | 15 |
Syntax: x,y denotes a variable or expression.
p denotes a pointer.
Precedence: 1 is the highest.