Arithmetic operator is a symbol that performs mathematical operation on data. C++ provides many arithmetic operators. Following is a list of all arithmetic operators in C++.
Operation | Symbol | Description |
Addition | + | Adds two values |
Subtraction | - | Subtracts one value from another value |
Multiplication | * | Multiplies two values |
Division | / | Divide one value by another value |
Modulus | % | Gives the remainder of division of two integers |
All arithmetic operators work with numeric values. Suppose we have two variables A and B where A = 10 and B = 5. Arithmetic operators can be used on A and B as follows :
Operation | Result |
A + B | 15 |
A - B | 5 |
A * B | 50 |
A / B | 2 |
A % B | 0 |
Some important points about modulus operator are as follows :
- Modulus operator is also called remainder operator.
- The modulus operator works only with integer values.
- In expression like 3 % 5, 3 is not divisible by 5. Its result is 3.
No comments:
Post a Comment