Welcome to the third post in our “C Programming Insights” series! Now that you’re familiar with variables and data types, let’s take a deeper dive into operators—the tools that allow you to perform calculations, compare values, and control program flow in C.
What Are Operators in C?
Operators are symbols that perform operations on variables and values. For example:
int result = 10 + 5;
Here, + is the arithmetic operator used to add two values.
Types of Operators in C
1. Arithmetic Operators
Used to perform basic mathematical operations:
| Operator | Description | Example |
|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulus (remainder) | a % b |
Example Code:
int a = 10, b = 3;
printf("Addition: %d\n", a + b);
printf("Remainder: %d\n", a % b);
Relational Operators
Used to compare two values, resulting in true (1) or false (0).
| Operator | Description | Example |
|---|---|---|
== | 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 | a <= b |
Example Code:
int x = 5, y = 10;
printf("x > y: %d\n", x > y); // Output: 0 (false)
3. Logical Operators
Used to combine or invert conditions.
| Operator | Description | Example |
|---|---|---|
&& | Logical AND (true if both true) | (a > 0) && (b > 0) |
| ` | ` | |
! | Logical NOT (invert truth value) | !(a > b) |
Example Code:
int a = 10, b = -5;
printf("Logical AND: %d\n", (a > 0) && (b > 0)); // Output: 0 (false)
Combining Operators in a Program
Here’s how you can use different types of operators together:
Example Program:
#include <stdio.h>
int main() {
int a = 15, b = 10, c = 5;
// Arithmetic
int sum = a + b + c;
// Relational
int isGreater = sum > 20;
// Logical
int check = (a > b) && (b > c);
printf("Sum: %d\n", sum);
printf("Is sum greater than 20? %d\n", isGreater);
printf("Logical check: %d\n", check);
return 0;
}
Output:
Sum: 30
Is sum greater than 20? 1
Logical check: 1
Programming Tips for Operators
- Use parentheses
()to make expressions clearer and avoid operator precedence issues. - Be careful with integer division; it truncates the decimal part.
- Example:
5 / 2 = 2(not 2.5).
- Example:
- Always test your conditions with edge cases to avoid logical errors.
Practice Problem
Write a program that:
- Takes two integers as input.
- Uses relational and logical operators to check if both numbers are positive.
- Displays the larger of the two numbers.
What’s Next?
In the next post, we’ll explore control structures in C, such as if, else, and loops, to create more dynamic and interactive programs.
Follow Us
Stay updated with isoftguide.in for more tips, tutorials, and career resources in programming and IT!

