Arithmetic operators perform mathematical calculations on numeric values. The values they operate on are called operands, and the result is a new value.
For a broader introduction to operators, see Operators.
Addition#
The + operator adds two values together.
int a = 3;
int b = 4;
int result = a + b; // 7a = 3
b = 4
result = a + b # 7let a = 3;
let b = 4;
let result = a + b; // 7
Subtraction#
The - operator subtracts the right operand from the left.
int result = 10 - 3; // 7result = 10 - 3 # 7let result = 10 - 3; // 7
Multiplication#
The * operator multiplies two values.
int result = 3 * 4; // 12result = 3 * 4 # 12let result = 3 * 4; // 12
Division#
The / operator divides the left operand by the right.
int result = 10 / 3; // 3 (integer division — decimal part dropped)
double precise = 10.0 / 3; // 3.333...In C#, dividing two integers always produces an integer. The decimal part is dropped, not rounded.
result = 10 / 3 # 3.333... (always float)
integer = 10 // 3 # 3 (floor division)let result = 10 / 3; // 3.333...
Modulo#
The % operator returns the remainder after division. It’s useful for checking whether a number is odd or even.
int remainder = 7 % 3; // 1 (7 divided by 3 is 2 with remainder 1)
int check = 4 % 2; // 0 (4 divides evenly by 2)remainder = 7 % 3 # 1
check = 4 % 2 # 0let remainder = 7 % 3; // 1
let check = 4 % 2; // 0
Checking Odd or Even#
A common use of modulo is checking whether a number is odd or even. Any number divided by 2 has a remainder of either 0 (even) or 1 (odd).
Combining modulo with a comparison operator produces a boolean result directly:
bool isEven = 4 % 2 == 0; // true
bool isOdd = 7 % 2 == 0; // falseThe expression evaluates left to right: 4 % 2 gives 0, then 0 == 0 gives true.
is_even = 4 % 2 == 0 # True
is_odd = 7 % 2 == 0 # Falselet isEven = 4 % 2 === 0; // true
let isOdd = 7 % 2 === 0; // false
Increment and Decrement#
The ++ and -- operators add or subtract 1 from a
variable. Commonly used in loops and counters.
int score = 0;
score++; // score is now 1
score--; // score is now 0Python has no ++ or -- operators. Use += 1 and -= 1 instead.
score = 0
score += 1 # score is now 1
score -= 1 # score is now 0let score = 0;
score++; // score is now 1
score--; // score is now 0
Common Mistakes#
Integer division dropping decimals silently in C#
10 / 3 gives 3 in C#, not 3.333. There’s no warning — the decimal is simply dropped. If you need a decimal result, make sure at least one operand is a double or float.
Confusing % with division
7 % 3 is 1, not 2.333. The modulo operator returns the remainder, not the quotient.
Using ++ on the wrong side
score++ and ++score both increment score, but they differ when used inside an expression. score++ returns the value before incrementing; ++score returns the value after. When used as a standalone statement they behave the same.
Adding a string and a number
In most languages, "score: " + 5 does not add numerically — it concatenates. The result is the string "score: 5". Use string interpolation instead of + when mixing text and numbers.
Dividing by zero Dividing any number by zero causes a runtime error. Always check that a divisor is non-zero before dividing.