Operators in C++ Part I

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

OperationDescription
a + bAdds a and b
a – bSubtracts b from a
a * bMultiplies a and b
a / bDivides a by b
a % bModulus of a and b
a++Post increments a by 1
a– Post decrements a by 1
++aPre increments a by 1
–aPre 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
Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in