Operators in C
An operator in C is a symbol that tells the compiler to perform an operation on one or more values — like + to add, == to compare, or && to combine conditions. Operators are the verbs of C: they turn variables and literals into results.
Arithmetic operators
These do the math: +, -, *, /, and % (modulo, the remainder).
#include <stdio.h>
int main(void) {
int a = 17, b = 5;
printf("Sum: %d\n", a + b); /* 22 */
printf("Quotient: %d\n", a / b); /* 3 -> integer division drops the fraction */
printf("Remainder: %d\n", a % b); /* 2 -> what's left after dividing */
return 0;
}
The % operator only works on integers and is great for "is it even?" (n % 2 == 0) or wrapping values around a range.
Relational and equality operators
These compare two values and return 1 (true) or 0 (false): <, >, <=, >=, ==, !=.
int x = 10;
printf("%d\n", x > 5); /* 1, true */
printf("%d\n", x == 10); /* 1, true */
printf("%d\n", x != 10); /* 0, false */
Remember: == compares, while a single = assigns. This is one of the most common bugs in C.
Logical operators
&& (AND), || (OR), and ! (NOT) combine true/false expressions. They are essential for if-else decisions.
int age = 20;
int hasID = 1;
if (age >= 18 && hasID) { /* both must be true */
printf("Allowed\n");
}
C uses short-circuit evaluation: in a && b, if a is false, b is never checked. This lets you safely write things like if (p != NULL && p->value > 0).
Want to learn this properly?
Join the waitlist for C Programming — beginner-friendly, project-first classes in Jalgaon.
Explore C ProgrammingAssignment and compound operators
= assigns. Compound forms combine an operation with assignment: +=, -=, *=, /=, %=.
int total = 100;
total += 50; /* same as: total = total + 50; -> 150 */
total /= 2; /* same as: total = total / 2; -> 75 */
Increment and decrement
++ adds one, -- subtracts one. Position matters:
int i = 5;
printf("%d\n", i++); /* prints 5, THEN i becomes 6 (post-increment) */
printf("%d\n", ++i); /* i becomes 7 first, THEN prints 7 (pre-increment) */
Bitwise operators (a peek ahead)
&, |, ^, ~, <<, >> work directly on the binary bits of integers. You will meet them in low-level work, embedded systems, and flag handling. Beginners can revisit these later.
Operator precedence
Operators have an order, just like math. * and / run before + and -; && runs before ||. When in doubt, use parentheses to make intent explicit and avoid surprises:
int r = (2 + 3) * 4; /* 20, not 14 */
Common mistakes
- Using
=instead of==inside a condition:if (x = 0)assigns and is always false; you meantif (x == 0). - Integer division losing the fraction:
7 / 2is3. Use adoubleoperand for3.5. - Confusing
&&/||with bitwise&/|: the logical ones short-circuit; the bitwise ones do not and operate on bits. - Relying on precedence you're unsure of — add parentheses.
- Modulo on floats:
%is integer-only; usefmod()from<math.h>for floating-point remainders.
FAQ
What does % do exactly? It gives the remainder after integer division, so 10 % 3 is 1.
Why does ++i differ from i++? Pre-increment changes the value before it's used in the expression; post-increment uses the old value first.
More basics on the hub C Programming, plus Variables & Data Types and If-Else in C.
Want to learn this properly? Join the waitlist for our C Programming course — taught in Jalgaon.
Want to learn this properly?
Join the waitlist for C Programming — beginner-friendly, project-first classes in Jalgaon.
Explore C ProgrammingFounder, Infoplanet
Atul Kabra founded Infoplanet in 2001 and has spent over two decades teaching programming — C, C++, Java, databases and more — to students across Maharashtra.
Related guides
Arrays in C
A beginner guide to arrays in C — declaring, initializing and indexing them, looping over elements, multidimensional arrays, and avoiding out-of-bounds errors.
Common C Errors & How to Fix Them
A troubleshooting guide to the most common C errors beginners face — from = vs ==, format mismatches and missing semicolons to segmentation faults — and how to fix each.
Dynamic Memory Allocation in C
A beginner guide to dynamic memory allocation in C — malloc, calloc, realloc and free, allocating at runtime, and preventing memory leaks.
