Arithmetic operators are special symbols used to perform mathematical operations in C++. The basic arithmetic operators are:
| Operator | Name | Description |
|---|---|---|
+ | 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 |
++ | Increment | Increases the value of a variable by one |
-- | Decrement | Decreases the value of a variable by one |
If you want to know more about arithmetic operators, check out this entry
List of Arithmetic Operators
Addition +
The addition operator allows us to add two values and get a result. For example:
int a = 5;
int b = 3;
int result = a + b; // result will be equal to 8
Copied!
Subtraction -
The subtraction operator allows us to subtract one value from another and get the result. For example:
int a = 10;
int b = 7;
int result = a - b; // result will be equal to 3
Copied!
Multiplication *
The multiplication operator allows us to multiply two values and get the result. For example:
int a = 4;
int b = 6;
int result = a * b; // result will be equal to 24
Copied!
Division /
The division operator allows us to divide one value by another and get the result. For example:
int a = 15;
int b = 3;
int result = a / b; // result will be equal to 5
Copied!
Modulus %
The modulus operator allows us to get 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
Copied!
