Arithmetic ( + - * / % )
Try it yourself →Four basic operations and remainder.
Syntax
a + b, a % b
Description
Integer division drops the decimal: 7 / 2 = 3. At least one must be double for decimals.
Example
#include <iostream>
using namespace std;
int main() {
cout << 7 % 2 << endl;
cout << 7 / 2 << endl;
cout << 7.0 / 2 << endl;
return 0;
}Expected output
1 3 3.5
When to use?
Calculations.
Common mistakes
- ⚠️ 7 / 2 = 3 (integer division). For decimals, 7.0 / 2.