C Programming Operators
Operators in C are special symbols used to perform operations on variables and values.
They tell the compiler what operation to perform, such as addition, comparison, assignment, or logical checks.
Types of Operators in C
C operators are classified into the following main types:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operators
- Increment and Decrement Operators
- Bitwise Operators
- Conditional (Ternary) Operator
sizeofOperator
1. Arithmetic Operators
Used to perform mathematical calculations.
| Operator | Operation |
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus (remainder) |
Example:
int a = 10, b = 3;
int sum = a + b;
int rem = a % b;2. Relational Operators
Used to compare two values.
The result is either true (1) or false (0).
| Operator | Meaning |
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
Example:
if (a > b) {
printf("a is greater");
}3. Logical Operators
Used to combine conditions.
| Operator | Meaning |
&& | Logical AND |
|| | Logical OR |
! | Logical NOT |
Example:
if (a > 0 && b > 0) {
printf("Both are positive");
}4. Assignment Operators
Used to assign values to variables.
| Operator | Example |
= | a = 10 |
+= | a += 5 |
-= | a -= 2 |
*= | a *= 3 |
/= | a /= 2 |
Example:
a += 5; // a = a + 55. Increment and Decrement Operators
Used to increase or decrease a value by 1.
| Operator | Meaning |
++ | Increment |
-- | Decrement |
Example:
int x = 5;
x++; // x becomes 66. Bitwise Operators
Used to perform operations at the bit level.
| Operator | Operation |
& | Bitwise AND |
| | Bitwise OR |
^ | Bitwise XOR |
~ | Bitwise NOT |
<< | Left shift |
>> | Right shift |
Example:
int a = 5, b = 3;
int c = a & b;7. Conditional (Ternary) Operator
Used as a short form of if–else.
Syntax:
(condition) ? value_if_true : value_if_false;Example:
int max = (a > b) ? a : b;8. sizeof Operator
Used to find the memory size of a data type or variable.
Example:
int x;
printf("%d", sizeof(x));Operator Precedence (Important Concept)
Operator precedence decides which operator is evaluated first.
Example:
int result = 10 + 5 * 2; // result = 20* has higher precedence than +.
Key Points
- Operators work on operands (variables or values)
- Relational and logical operators return boolean results
- Bitwise operators work at the binary level
- Correct operator usage avoids logical and runtime errors
One-Line Exam Answer
Operators in C are symbols that perform operations on variables and values to produce a result.
