Introduction
Arithmetic operators allow you to perform mathematical calculations on numeric values. Dart supports all standard arithmetic operators you would expect from a modern programming language.
Why It Matters
Every program that deals with numbers — from calculators to games to financial apps — relies on arithmetic operators. Understanding them is a fundamental building block of programming logic.
Arithmetic Operators
| Operator | Name | Example | Result |
+ | Addition | 10 + 3 | 13 |
- | Subtraction | 10 - 3 | 7 |
* | Multiplication | 10 * 3 | 30 |
/ | Division (double) | 10 / 3 | 3.333... |
~/ | Integer division | 10 ~/ 3 | 3 |
% | Modulo (remainder) | 10 % 3 | 1 |
-expr | Unary minus (negate) | -10 | -10 |
Code Example
void main() {
int a = 20;
int b = 6;
print(a + b); // 26
print(a - b); // 14
print(a * b); // 120
print(a / b); // 3.3333333333333335
print(a ~/ b); // 3 (integer division, no decimal)
print(a % b); // 2 (remainder of 20 / 6)
print(-a); // -20
// Increment and decrement
int count = 5;
count++;
print(count); // 6
count--;
print(count); // 5
// Combined with doubles
double price = 19.99;
double tax = price * 0.1;
print(price + tax); // 21.989
}
Output:
26
14
120
3.3333333333333335
3
2
-20
6
5
21.989
Explanation
+ adds two numbers together.
- subtracts the right operand from the left.
* multiplies two numbers.
/ always returns a double, even if the result is a whole number.
~/ returns only the integer part of division (truncates the decimal).
% returns the remainder after integer division — very useful for checking even/odd numbers.
++ and -- increment or decrement a variable by 1.
Notes
- In Dart,
10 / 2 returns 5.0 (a double), not 5 (an int). Use ~/ if you need an integer result.
- The
++ operator can be prefix (++x) or postfix (x++). Prefix increments before use; postfix increments after use.
- Dividing by zero with
/ on doubles produces Infinity; dividing integers with ~/ throws an exception.
Common Mistakes
- Using
/ when you need an integer result — use ~/ instead.
- Forgetting that
int + double produces a double in Dart.
- Confusing
% (modulo) with percentage — 10 % 3 is 1, not 0.1.
💪 Exercise
- Write a program that takes two integers
a = 17 and b = 5 and prints the result of all six arithmetic operators.
- Check if the number 42 is even using the modulo operator.
- Calculate the area of a rectangle with width
8.5 and height 4.2.
🧠 Quiz
1. What does 15 ~/ 4 return in Dart?
2. Which operator gives the remainder of division?
Summary
Dart's arithmetic operators cover addition (+), subtraction (-), multiplication (*), division (/), integer division (~/), and modulo (%). Remember that / always returns a double. Use ~/ when you need a whole-number result and % to find remainders.