C Operators

Arithmetic
=assignment
+addition
-subtraction
*multiplication
/division
%modulus
++increment
--decrement

Logical and relational
&&AND
||OR
!NOT
==equal
!=not equal
<less than
<=less than or equal
>greater than
>=greater than or equal

Bitwise
&AND
|OR
^XOR
~NOT (one's complement)
<<shift left (multiply by 2)
>>shift right (divide by 2)


The unary operators are ++, --, - (negative), ! and ~

The operators << and >> take as their right-hand argument the number of places to shift the bits.


Precedence

  1.   !   ~   - (negative)   ++   --
  2.   *   /   %
  3.   +   -
  4.   <<   >>
  5.   <   <=   >   >=
  6.   ==   !=
  7.   &
  8.   ^
  9.   |
  10.   &&
  11.   ||
  12.   ?:
  13.   =   +=   -=   *=   /=   etc.


Logical and Bitwise arithmatic

P Q ~P P & Q P | Q P ^ Q
1 1 0 1 1 0
1 0 0 0 1 1
0 1 1 0 1 1
0 0 1 0 0 0

~(P & Q) is the same as ~P | ~Q

~(P | Q) is the same as ~P & ~Q