In C programming, operators are special symbols that perform operations on variables and values. Operators allow us to manipulate data and perform calculations.
📘 Key Operator Types:
These operators perform basic mathematical operations on numeric values.
int a = 10, b = 5; int sum = a + b; // Addition int diff = a - b; // Subtraction int prod = a * b; // Multiplication int div = a / b; // Division int mod = a % b; // Modulo (Remainder)
Relational operators are used to compare two values and return a boolean result (True or False).
int a = 10, b = 5; a == b // Equal to a != b // Not equal to a > b // Greater than a < b // Less than a >= b // Greater than or equal to a <= b // Less than or equal to
Logical operators are used to perform logical operations on boolean values.
int a = 10, b = 5; (a > b) && (b > 0) // AND (a > b) || (b > 0) // OR !(a > b) // NOT
Assignment operators are used to assign values to variables.
int a = 10; a += 5 // a = a + 5 a -= 5 // a = a - 5 a *= 5 // a = a * 5 a /= 5 // a = a / 5 a %= 5 // a = a % 5
These operators are used to increase or decrease the value of a variable by 1.
int a = 10; a++; // Increment (a = a + 1) a--; // Decrement (a = a - 1)
Bitwise operators perform operations on individual bits of integer values.
int a = 5, b = 3; a && b // AND a | b // OR a ^ b // XOR ~a // NOT a << 1 // Left Shift a >> 1 // Right Shift
The ternary operator is a shorthand way to express an if-else statement.
int a = 10, b = 5; int result = (a > b) ? a : b; // If a > b, result = a; else result = b;
The sizeof
operator is used to determine the size of a data type or variable in bytes.
int a = 10; printf("Size of int: %lu bytes", sizeof(a)); // Output the size of a
=
) instead of the equality operator (==
).Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!