Arithmetic operators are special symbols that are used to perform mathematical operations in C++. The basic arithmetic operators are:
+
(Addition): Adds two values.-
(Subtraction): Subtracts the second value from the first.*
(Multiplication): Multiplies two values./
(Division): Divides the first value by the second.%
(Modulus): Returns the remainder of the division of the first value by the second.
More information about arithmetic operators read more ⯈
List of arithmetic operators
Addition (+)
The addition operator allows us to add two values and obtain a result. For example:
int a = 5;
int b = 3;
int result = a + b; // result will be equal to 8
Subtraction (-)
The subtraction operator allows us to subtract one value from another and obtain the result. For example:
int a = 10;
int b = 7;
int result = a - b; // result will be equal to 3
Multiplication (*)
The multiplication operator allows us to multiply two values and obtain the result. For example:
int a = 4;
int b = 6;
int result = a * b; // result will be equal to 24
Division (/)
The division operator allows us to divide one value by another and obtain the result. For example:
int a = 15;
int b = 3;
int result = a / b; // result will be equal to 5
Modulus (%)
The modulus operator allows us to obtain the remainder of the division between two values. For example:
int a = 17;
int b = 5;
int result = a % b; // result will be equal to 2