100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Arithmetic Operators in C++

Learn how C++ arithmetic operators (+, -, *, /, %) work, including integer division truncation and modulo rules, with runnable examples.

OperatorsBeginner6 min readJul 7, 2026
Analogies

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

cpp
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

cpp
#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

text
a + b = 22
a - b = 12
a * b = 85
a / b = 3
a % b = 2
(double)a / b = 3.4

6. Key Takeaways

  • C++ arithmetic operators are +, -, *, /, and %.
  • Integer / truncates toward zero; it does not round.
  • % (modulo) only works on integer operands, not float/double.
  • Casting an operand to double forces real (non-truncated) division.

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#ArithmeticOperatorsInC#Arithmetic#Operators#Syntax#Explanation#StudyNotes#SkillVeris#ExamPrep