C Operators
Defination
Operators in C are symbols or tokens that instruct the compiler to execute calculations, evaluations, or modifications on values or memory units. These tools allow your logic to interact with data directly.
Types of Operators
1. Arithmetic Operators
Used for mathematical handling involving numbers.
| Symbol | Purpose | Sample |
|---|---|---|
| + | Join values | x + y |
| - | Reduce one | x - y |
| * | Multiply | x * y |
| / | Divide | x / y |
| % | Find remainder | x % y |
2. Relational Operators
Establish comparisons between two quantities and return a logical result.
| Symbol | Implication | Instance |
|---|---|---|
| =#ERR520! | Checks sameness | a == b |
| != | Validates mismatch | a != b |
| > | Larger-than check | a > b |
| < | Smaller-than check | a < b |
| >= | Greater or equal | a >= b |
| <= | Lesser or equal | a <= b |
3. Logical Operators
Decide truthfulness based on combined conditions.
| Symbol | Logic Type | Example |
|---|---|---|
| && | All must be true | x && y |
| ` | ` | |
| ! | Reverse boolean | !x |
4. Assignment Operators
These are used to inject values into containers (variables).
| Symbol | Task | Example |
|---|---|---|
| = | Directly stores | x = 20 |
| += | Adds, then stores | x += 5 |
| -= | Subtracts, then stores | x -= 2 |
| *= | Multiplies, then stores | x *= 3 |
| /= | Divides, then stores | x /= 2 |
| %= | Stores leftover | x %= 4 |
5. Unary Operators
Affect a single operand directly.
| Operator | Impact | Illustration |
|---|---|---|
| ++ | Add one | ++x or x++ |
| -- | Subtract one | --x or x-- |
| + | Affirms sign | +x |
| - | Negates sign | -x |
6. Bitwise Operators
Operate at the individual bit level, enabling low-level data control.
| Symbol | Function | Sample |
|---|---|---|
| & | Bitwise AND | x & y |
| ` | ` | Bitwise OR |
| ^ | Bitwise XOR | x ^ y |
| ~ | Bit flip | ~x |
| << | Bit shift left | x << 2 |
| >> | Bit shift right | x >> 2 |
7. Ternary Operator
A concise method for choosing between two results based on a condition.
Syntax:
(condition) ? result1 : result2;
Sample:
int max = (a > b) ? a : b;
8. Type Conversion Operator
Helps you explicitly switch data types using casting.
Example:
float result = (float)5 / 2;
9. Size and Address Operators
Useful tools to manage memory and type details.
| Symbol | Action | Example |
|---|---|---|
| sizeof | Measures byte length | sizeof(int) |
| & | Acquires memory address | &var |
| * | Accesses pointer value | *ptr |
Important Reminders
- Use parentheses to control priority.
- Master the precedence chart to decode which operators take control first in an expression.
- Using bitwise operators where logical ones are intended can lead to unpredictable and often erroneous outcomes.
Summary Chart
| Operator Type | Common Symbols |
|---|---|
| Arithmetic | +, -, *, /, % |
| Relational | ==, =, <, > |
| Logical | &&, ` |
| Assignment | =, +=, -= |
| Unary | ++, -- |
| Bitwise | &, ` |
| Ternary | ? : |
| Type Casting | (type) |
| Miscellaneous | sizeof, &, * |
Prefer Learning by Watching?
Watch these YouTube tutorials to understand C Tutorial visually:
What You'll Learn:
- 📌 #6: C Operators | [2025] C Programming for Beginners
- 📌 C_13 Operators in C - Part 1 | Unary , Binary and Ternary Operators in C | C programming Tutorials