wleci
AboutProjectsBlogContact
Contact
Back to blog
INF.04ProgrammingMath

Mathematical Operators: The Foundation of Computing

Learn basic and advanced mathematical operators. Understand how modulo, incrementation works, and why operator precedence matters.

December 25, 20253 min read
Share:

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

A symbol or word that tells the compiler/interpreter to perform a specific mathematical operation on given values (operands).

Basic Operators

Here is the set of tools you will find in almost every programming language (C++, Java, Python, JS).

CechaSymbolName
+Addition5 + 2
-Subtraction5 - 2
*Multiplication5 * 2
/Division5 / 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

If you divide two integers (int), the result will always be truncated to an integer. Example: 5 / 2 results in 2, not 2.5! To get 2.5, at least one number must be a double/float (e.g., 5.0 / 2).

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

`++i` (pre): increments first, then returns the value. `i++` (post): returns the old value first, then increments. This can lead to very subtle logic bugs.

Example: Modulo in Practice

The % (modulo) operator is extremely useful, for example, for checking if a number is even:

cpp
int number = 10; if (number % 2 == 0) { // Number is even }

Pro Tips

Operator Precedence

Programs follow mathematical order of operations (multiplication before addition). Always use parentheses `()` to ensure calculations happen as intended. This also improves code readability.

Calculation Checklist

Rules for safe calculations

0/4

Quiz: 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

INF.04Programming

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.

2 min read
INF.04Programming

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.

2 min read
INF.04Programming

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.

3 min read
Back to blog
wleci.pl

Full-stack Developer

I build modern web applications with passion for clean code and good design.

[email protected]
Poland

Navigation

  • Home
  • About
  • Projects
  • Blog
  • Contact

Services

  • Web applications
  • Websites
  • API & Backend
  • Consulting

Technologies

  • React / Next.js
  • TypeScript
  • Node.js
  • PostgreSQL

Social

© 2026 wleci.pl. All rights reserved.

Privacy policy•Terms of service

Made with in Poland