C Operators
An operator is a symbol or keyword that tells C to perform an operation.
- Arithmetic operators
| Operator | Meaning | Example (a=10,b=3) |
| + | Addition | a + b = 13 |
| – | Subtraction | a – b = 7 |
| * | Multiplication | a * b = 30 |
| / | Division | a / b = 3 (integer division) |
| % | Remainder | a % b = 1 |
- Relational operators
These compare two values. In a condition, the result is treated as true or false.
| == equal to != not equal to > greater than < less than >= greater than or equal to <= less than or equal to |
- Logical operators
| && AND → both conditions must be true || OR → at least one condition is true ! NOT → reverses a condition |
- Assignment operators
| = += -= *= /= %= |
- Increment and decrement
| x++; // increase by 1 x–; // decrease by 1 |
- Bitwise operators
| & AND | OR ^ XOR ~ NOT << left shift >> right shift |
Bitwise operators work on the individual bits of integer values.
- Conditional operator
| condition ? value_if_true : value_if_false; |
- sizeof
| sizeof(variable_or_type) |
Complete operator program
| #include <stdio.h> int main() { printf(“Addition = %d\n”, a + b); if (a > b && b > 0) { return 0; |
| OUTPUT Addition = 13 Subtraction = 7 Multiplication = 30 Division = 3 Remainder = 1 Both conditions are true. |
| ⭐ EASY TIP: The = operator assigns a value. The == operator compares two values. This is one of the most common beginner mistakes. |