Operators are unique symbols that are employed to carry out certain tasks or activities. Both unary and binary options are possible. For instance, the binary operator + is used in C++ to accomplish addition when it is placed between two numbers. Operators come in a variety of forms. These are what they are:
Arithmetic Operators
Mathematical operations like addition, subtraction, etc. are carried out using arithmetic operators. They could be binary or unary. Several of the basic arithmetic operators include
Operation | Description |
a + b | Adds a and b |
a – b | Subtracts b from a |
a * b | Multiplies a and b |
a / b | Divides a by b |
a % b | Modulus of a and b |
a++ | Post increments a by 1 |
a– | Post decrements a by 1 |
++a | Pre increments a by 1 |
–a | Pre decrements a by 1 |
#include <iostream>
using namespace std;
int main()
{
int a = 4, b = 5;
cout << "The value of a + b is " << a + b << endl;
cout << "The value of a - b is " << a - b << endl;
cout << "The value of a * b is " << a * b << endl;
cout << "The value of a / b is " << a / b << endl;
cout << "The value of a % b is " << a % b << endl;
cout << "The value of a++ is " << a++ << endl;
cout << "The value of a-- is " << a-- << endl;
cout << "The value of ++a is " << ++a << endl;
cout << "The value of --a is " << --a << endl;
}
Output:
The value of a + b is 9
The value of a - b is -1
The value of a * b is 20
The value of a / b is 0
The value of a % b is 4
The value of a++ is 4
The value of a-- is 5
The value of ++a is 5
The value of --a is 4