1. Intro
Arithmetic operators perform mathematical computations on numeric operands. C++ provides five basic arithmetic operators: + (addition), - (subtraction), * (multiplication), / (division), and % (modulo, or remainder). These are binary operators, meaning they act on two operands, and they are used constantly in expressions, loop counters, and calculations.
Cricket analogy: Calculating a batsman's strike rate combines runs and balls faced using division, while working out required run rate blends addition, subtraction, and multiplication—arithmetic operators like +, -, *, /, and % are the building blocks scorers use every over.
2. Syntax
result = operand1 + operand2;
result = operand1 - operand2;
result = operand1 * operand2;
result = operand1 / operand2;
result = operand1 % operand2;3. Explanation
+, -, and * behave as expected on both integers and floating-point numbers. The / operator performs **integer division** when both operands are integers, meaning the result is truncated toward zero (the fractional part is discarded) — 7 / 2 gives 3, not 3.5. If either operand is a float or double, / performs real division and keeps the decimal part. The % operator returns the remainder of integer division and only works with integer operands; using it on float or double is a compile error (use fmod() from <cmath> instead).
Cricket analogy: When a team scores 275 in 50 overs, computing an even run rate with integer overs truncates fractions just like 7 / 2 gives 3 in C++, discarding the leftover 0.5 rather than rounding it.
Integer division truncates toward zero, it does not round. 7 / 2 is 3, and -7 / 2 is -3 (not -4). To get a floating-point result from integer operands, cast at least one operand: (double)7 / 2 gives 3.5.
4. Example
#include <iostream>
using namespace std;
int main() {
int a = 17, b = 5;
cout << "a + b = " << (a + b) << endl;
cout << "a - b = " << (a - b) << endl;
cout << "a * b = " << (a * b) << endl;
cout << "a / b = " << (a / b) << endl;
cout << "a % b = " << (a % b) << endl;
cout << "(double)a / b = " << ((double)a / b) << endl;
return 0;
}5. Output
a + b = 22
a - b = 12
a * b = 85
a / b = 3
a % b = 2
(double)a / b = 3.46. Key Takeaways
- C++ arithmetic operators are
+,-,*,/, and%. - Integer
/truncates toward zero; it does not round. %(modulo) only works on integer operands, notfloat/double.- Casting an operand to
doubleforces real (non-truncated) division.
Practice what you learned
1. What is the result of `17 / 5` in C++ when both operands are `int`?
2. What does `-7 / 2` evaluate to in C++?
3. Which operator returns the remainder of integer division?
4. What happens if you try `5.0 % 2.0` in C++?
5. What is the output of `cout << (double)7 / 2;`?
Was this page helpful?
You May Also Like
Relational Operators in C++
Understand C++ relational (comparison) operators such as ==, !=, <, >, <=, and >=, and how they always evaluate to a bool result.
Assignment Operators in C++
Learn C++ assignment operators including =, +=, -=, *=, /=, and %=, and how compound assignment shortens common update expressions.
Operator Precedence and Associativity in C++
Understand how C++ operator precedence and associativity determine evaluation order in complex expressions, with common gotchas explained.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics