Mathematical Operators: The Foundation of Computing
Learn basic and advanced mathematical operators. Understand how modulo, incrementation works, and why operator precedence matters.
Mathematical Operators
At its core, a computer is a powerful calculator. To perform calculations, we use mathematical operators. You know most of them from school, but in programming, they have specific rules, especially regarding data types.
Mathematical Operator
Basic Operators
Here is the set of tools you will find in almost every programming language (C++, Java, Python, JS).
| Cecha | Symbol | Name |
|---|---|---|
| + | Addition | 5 + 2 |
| - | Subtraction | 5 - 2 |
| * | Multiplication | 5 * 2 |
| / | Division | 5 / 2 |
| % | Modulo (Remainder) | 5 % 2 |
The Trap: Integer vs Floating-Point Division
This is a common cause of errors in coding tasks. The result of division depends on the data types of the numbers.
Division in C++ / Java
Increment and Decrement
Used to quickly increase or decrease a value by 1. Very popular in loops.
++(Increment): increases by 1--(Decrement): decreases by 1
Pre- vs Post-increment
Example: Modulo in Practice
The % (modulo) operator is extremely useful, for example, for checking if a number is even:
int number = 10;
if (number % 2 == 0) {
// Number is even
}Pro Tips
Operator Precedence
Calculation Checklist
Rules for safe calculations
0/4Quiz: Check Your Knowledge
What is the result of 7 % 3 in most programming languages?
Operator Hierarchy (Mermaid)
What's Next?
- Learn about Assignment Operators (e.g.,
+=,*=) that shorten your code. - Check out Comparison Operators (e.g.,
==,!=), essential for conditional statements. - Read about the Math Class (in Java/JS) or the
<cmath>header (in C++), which allow for power and square root functions. - Practice INF.04-style tasks requiring calculations with integer and floating-point types.
You might also like
Relational and Logical Operators: How to Compare Data?
Understand how comparison operators work and how to combine conditions using AND, OR, and NOT. Essential knowledge for control statements.
Conditional Operator: Short-hand if-else in one line
Learn the ternary operator. Find out how to shorten your code and when to use it instead of classic if-else statements.
Reserved Keywords: List of Key Terms in IT
Understand what keywords are in programming languages. Learn why you can't use them as variable names and see lists for C++, Java, and Python.