C++ arithmetic operators perform mathematical calculations on numeric values. In this tutorial, you will learn how to use addition, subtraction, multiplication, division, modulus, increment, and decrement operators, along with important rules for integer division, operator precedence, and prefix versus postfix forms.

C++ Arithmetic Operators and Their Symbols

Arithmetic operators work with operands such as variables, constants, and numeric expressions. For example, in a + b, a and b are operands and + is the addition operator.

C++ Arithmetic Operator Tutorials

C++ Arithmetic Operators List

The following table shows the commonly used arithmetic operators in C++, their symbols, and what each expression does.

Arithmetic OperationOperator SymbolExampleDescription
Addition+a + bReturns the sum of a and b.
Subtractiona – bSubtracts b from a.
Multiplication*a * bReturns the product of a and b.
Division/a / bReturns the quotient when a is divided by b.
Modulus%a % bReturns the remainder when integer a is divided by integer b.
Increment++a++ or ++aIncrements the value of a by one.
Decrementa– or –aDecrements the value of a by one.

C++ Arithmetic Operator Syntax

Binary arithmetic operators such as +, -, *, /, and % use two operands. Increment and decrement are unary operators and use one operand.

</>
Copy
result = operand1 + operand2;
result = operand1 - operand2;
result = operand1 * operand2;
result = operand1 / operand2;
result = operand1 % operand2;

++value;
--value;

C++ Arithmetic Operators with Example Programs

C++ Addition Operator (+)

The + operator adds its two operands and returns their sum.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
   int a = 12;
   int b = 7;

   int sum = a + b;

   cout << "Addition : " << sum << endl;
}

Output

Addition : 19
Program ended with exit code: 0

Here, 12 + 7 evaluates to 19. Learn more about C++ Addition.

C++ Subtraction Operator (-)

The - operator subtracts the right operand from the left operand.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
   int a = 12;
   int b = 7;

   int diff = a - b;

   cout << "Subtraction : " << diff << endl;
}

Output

Subtraction : 5
Program ended with exit code: 0

Here, 12 - 7 evaluates to 5. Learn more about C++ Subtraction.

C++ Multiplication Operator (*)

The * operator multiplies its two operands and returns their product.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
   int a = 12;
   int b = 7;

   int product = a * b;

   cout << "Multiplication : " << product << endl;
}

Output

Multiplication : 84
Program ended with exit code: 0

Here, 12 * 7 evaluates to 84. Learn more about C++ Multiplication.

C++ Division Operator (/)

The / operator divides the left operand by the right operand and returns the quotient. The result depends on the operand types. When both operands are integers, C++ performs integer division and discards the fractional part.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
   int a = 16;
   int b = 7;

   int div = a / b;

   cout << "Quotient : " << div << endl;
}

Output

Quotient : 2
Program ended with exit code: 0

The expression 16 / 7 uses two int operands, so the result is 2, not approximately 2.2857. Learn more about C++ Division.

C++ Modulus Operator (%)

The % operator returns the remainder after integer division. For example, 13 % 5 is 3 because 13 divided by 5 leaves a remainder of 3.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
   int a = 13;
   int b = 5;

   int modulo = a%b;

   cout << "Remainder : " << modulo << endl;
}

Output

Remainder : 3
Program ended with exit code: 0

In C++, the built-in remainder operator is used with integral operand types. Learn more about C++ Modular Division.

C++ Increment Operator (++)

The ++ operator increases the value of its operand by one. It can be written in prefix form as ++a or postfix form as a++.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
   int a = 12;
   ++a;
   cout << "Incremented value : " << a << endl;
}

Output

Incremented value : 13
Program ended with exit code: 0

When increment is used as a statement by itself, both ++a and a++ increase a by one. Their difference matters when the expression’s value is used elsewhere. Learn more about C++ Increment.

C++ Decrement Operator (–)

The -- operator decreases the value of its operand by one. It can be written in prefix form as --a or postfix form as a--.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
   int a = 12;
   --a;
   cout << "Decremented value : " << a << endl;
}

Output

Decremented value : 11
Program ended with exit code: 0

When decrement is used as a statement by itself, both --a and a-- decrease a by one. Learn more about C++ Decrement.

Integer Division and Floating-Point Division in C++

A common source of confusion is that / does not always produce a decimal result. If both operands have integral types, the result is integral and the fractional part is discarded. If at least one operand is a floating-point value, floating-point division is performed.

</>
Copy
#include <iostream>
using namespace std;

int main() {
    int a = 7;
    int b = 2;

    cout << a / b << endl;
    cout << static_cast<double>(a) / b << endl;

    return 0;
}

Output

3
3.5

In the first expression, both operands are integers. In the second, a is converted to double before division, so the fractional result is retained.

Prefix and Postfix Increment and Decrement in C++

Prefix and postfix forms both modify the operand, but an expression can observe a different value. Prefix increment or decrement modifies the operand first and then yields the modified value. Postfix increment or decrement yields the original value and then modifies the operand.

</>
Copy
#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 5;

    int x = ++a;
    int y = b++;

    cout << "a = " << a << ", x = " << x << endl;
    cout << "b = " << b << ", y = " << y << endl;

    return 0;
}

Output

a = 6, x = 6
b = 6, y = 5

Arithmetic Operator Precedence in C++

When an expression contains more than one arithmetic operator, C++ uses operator precedence and associativity to determine how the expression is grouped. Multiplication, division, and modulus have higher precedence than addition and subtraction.

PrecedenceArithmetic OperatorsAssociativity
Highest among those shownPostfix value++, value--Left to right
NextPrefix ++value, --value, unary +, unary -Right to left
Next*, /, %Left to right
Next+, -Left to right

For example, 2 + 3 * 4 evaluates to 14 because multiplication is performed before addition. Parentheses can be used when you want a different grouping.

</>
Copy
#include <iostream>
using namespace std;

int main() {
    cout << 2 + 3 * 4 << endl;
    cout << (2 + 3) * 4 << endl;

    return 0;
}

Output

14
20

Unary Plus and Unary Minus in C++ Arithmetic Expressions

C++ also uses + and - as unary operators. Unary plus leaves the numeric value unchanged, while unary minus produces the negated value.

</>
Copy
#include <iostream>
using namespace std;

int main() {
    int value = 8;

    cout << +value << endl;
    cout << -value << endl;

    return 0;
}

Output

8
-8

Division by Zero and Modulus by Zero in C++

Do not divide an integer by zero or use zero as the right operand of the integer modulus operator. For built-in integral types, these operations have undefined behavior. A program should check the divisor before evaluating the expression.

</>
Copy
#include <iostream>
using namespace std;

int main() {
    int a = 20;
    int b = 0;

    if (b != 0) {
        cout << a / b << endl;
        cout << a % b << endl;
    } else {
        cout << "Divisor must not be zero." << endl;
    }

    return 0;
}

Output

Divisor must not be zero.

C++ Arithmetic Operators: Practical Rules to Remember

  • Use +, -, *, and / for the four basic arithmetic operations.
  • Use % when you need the remainder of integral division.
  • Remember that integer division discards the fractional part.
  • Convert at least one operand to a floating-point type when you need a fractional quotient.
  • Use parentheses when the intended calculation should not rely on default operator precedence.
  • Distinguish prefix and postfix ++ or -- when the expression’s value is also being used.
  • Check that an integral divisor is not zero before using / or %.

C++ Arithmetic Operators Summary

In this C++ Tutorial, we learned how the arithmetic operators +, -, *, /, %, ++, and -- work. We also covered integer versus floating-point division, prefix and postfix forms, unary arithmetic operators, precedence, and division-by-zero checks.