An operator in a programming language is a symbol that tells the compiler or interpreter to perform a specific mathematical, relational or logical operation and produce a final result.
Operator | Description |
== | is equal to |
< | is less than |
> | is greater than |
<= | is less than or equal to |
>= | is greater than or equal to |
!= | is not equal to |
a = b ? c : d; is equivalent to: if (b) a = c; else a = d;
Operator | Description |
>> | Right shift |
<< | Left shift |
^ | Bitwise xor |
~ | One's complement |
& | Bitwise AND |
| | Bitwise OR |
Operator | Description |
&& | AND |
|| | OR |
! | NOT |
Operator | Description |
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus |
++ | Increment |
-- | Decrement |
var = expression; int x, y, z; x = y = z = 100; // set x, y, and z to 100
int a = 1; int b = 1; int tmp = 0; tmp = ++a; /* increments a by one, and returns new value; a == 2, tmp == 2 */ tmp = a++; /* increments a by one, but returns old value; a == 3, tmp == 2 */ tmp = --b; /* decrements b by one, and returns new value; b == 0, tmp == 0 */ tmp = b--; /* decrements b by one, but returns old value; b == -1, tmp == 0 */