Definition
📌 Operators
Operators are symbols that perform operations on variables and values: doing math, comparing values, or combining logical conditions.C groups operators into a few families: arithmetic, relational (comparison), logical, and assignment..
Syntax
syntax
a + b a - b a * b a / b a % b
a == b a != b a > b a < b
a && b a || b !a
a = b a += b a -= bExample
c
#include <stdio.h>
int main() {
int a = 10, b = 3;
printf("Sum: %d\n", a + b);
printf("Remainder: %d\n", a % b);
printf("Is equal: %d\n", a == b);
return 0;
}Output
outputSum: 13
Remainder: 1
Is equal: 0
Important Points
%only works with integers, notfloat/double.&&and||short-circuit — the second condition may not be evaluated.- Integer division truncates:
7 / 2gives3, not3.5. - Compound assignment operators like
+=make code shorter:x += 5isx = x + 5.
Common Mistakes
- Confusing
=(assignment) with==(comparison) inside anif. - Expecting
7 / 2to give a decimal result when both operands areint. - Forgetting operator precedence — use parentheses when in doubt.
Interview Tip
🎯 Before your interview
"Why does 7/2 give 3 in C?" is a classic gotcha — because integer division truncates the decimal part.
