A unary operator takes exactly one operand, which is why it binds more tightly than any binary operator: in -a * b the minus applies to a before the multiplication happens.
| Operator | Name | Works On | Meaning |
|---|---|---|---|
+x | Unary plus | Numeric | Promotes its operand and changes nothing |
-x | Unary minus | Numeric | Promotes and negates |
++x | Prefix increment | Variable only | Increment, then yield the new value |
x++ | Postfix increment | Variable only | Yield the old value, then increment |
--x | Prefix decrement | Variable only | Decrement, then yield the new value |
x-- | Postfix decrement | Variable only | Yield the old value, then decrement |
!b | Logical complement | boolean only | Inverts true and false |
~n | Bitwise complement | Integral types only | Flips every bit |
There is no unary "not a number" operator, and no unary version of %, *, or /. Note also that - and + in this table are the single-operand forms: a - b is binary subtraction and is a completely different operator that merely shares a symbol.