Arithmetic Operators in C
C arithmetic uses the familiar five: + - * / % (modulo). The critical rule is that / on two integers performs truncating integer division — 7 / 2 is 3, not 3.5 — while mixing in any floating operand promotes the whole expression. The % operator works only on integers and yields the remainder: the backbone of divisibility tests, wrapping indexes, and digit extraction.
Compound forms (+=, -=, *=, /=, %=) combine operation with assignment, and prefix/postfix ++ and -- step by one with different timing: ++i increments before use, i++ after.
The five operators
+ - * / % cover addition through remainder. % accepts integers only — 7.5 % 2 refuses to compile.
Integer division truncates
Both operands int means the fraction is discarded toward zero: 7 / 2 == 3 and -7 / 2 == -3.
Mixed types promote
One double operand lifts everything to double: 7 / 2.0 == 3.5. The usual fix for accidental truncation is casting one side.
Compound and increment forms
x += 2 beats x = x + 2 for brevity; ++i vs i++ differ only in when the increment lands relative to the expression.
#include <stdio.h> int main(void) { int total = 7, n = 2; printf("%d\n", total / n); printf("%d\n", total % n); printf("%.1f\n", total / 2.0); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.