Arithmetic ( + - * / % )
Try it yourself →Four basic operations and remainder.
Syntax
a + b, a % b
Description
Integer division truncates the decimal: 7 / 2 = 3. Use float/double for decimals.
Example
#include <stdio.h>
int main() {
printf("%d\n", 7 % 2);
printf("%d\n", 7 / 2);
printf("%.1f\n", 7.0 / 2);
return 0;
}Expected output
1 3 3.5
When to use?
Calculations.
Common mistakes
- ⚠️ 7 / 2 = 3 (int division). Use 7.0 / 2 for decimals.