C - Operators
Category | Operator | Description | Example |
Arithmetic Operators | + | Addition | int result = 5 + 3; |
- | Subtraction | int result = 5 - 3; | |
* | Multiplication | int result = 5 * 3; | |
/ | Division | int result = 5 / 3; | |
% | Modulo (Remainder) | int result = 5 % 3; | |
Assignment Operators | = | Assigns a value to a variable | int x = 5; |
+= | Adds and assigns | x += 3; | |
-= | Subtracts and assigns | x -= 3; | |
*= | Multiplies and assigns | x *= 3; | |
/= | Divides and assigns | x /= 3; | |
%= | Calculates modulus and assigns | x %= 3; | |
Increment/Decrement | ++ | Increment by 1 | x++; or ++x; |
-- | Decrement by 1 | x--; or --x; | |
Comparison Operators | == | Equality | if (x == y) |
!= | Inequality | if (x != y) | |
> | Greater than | if (x > y) | |
< | Less than | if (x < y) | |
>= | Greater than or equal to | if (x >= y) | |
<= | Less than or equal to | if (x <= y) | |
Logical Operators | && | Logical AND | if (x > 0 && y > 0) |
|| | Logical OR | if (x > 0 || y > 0) | |
! | Logical NOT | if (!x) |