Home | Computer | Arithmetic Operator in C++ | Addition, Subtraction, Multiplication, Division, Modulus

# Arithmetic Operator in C++ | Addition, Subtraction, Multiplication, Division, Modulus

August 22, 2022 written by Sehrish Basharat

Arithmetic operators are very important in C++. They allow us to add, subtract or multiply numbers together. In programming, they play a vital role in our programs. For example, we might want to calculate the sum of two numbers.

Addition (+): The result of adding two numbers together. Subtraction (-): The result of subtracting one number from another. Multiplication (*): The result of multiplying two numbers together.

The addition operator is used to add two values or two variables. The symbol of the addition operator is “+”

For Example

a + b;  , 5 + 6 = 11

Int main()

{

Int a, b;

a = 5;

b = 4;

cout << “a + b =” << a + b <<endl;

}

## Subtraction Operatorin C++

This operator is used to subtract the two numbers or variables. The symbol used to subtract the number is “-”.

For example

a – b;   , 10 – 2 = 8

Int main()

{

Int a, b;

a = 10;

b = 4;

cout << “a – b =” << (a – b) <<endl;

}

## Multiplication operatorin C++

This operator is used to multiply the two numbers and variables. The symbol of multiplication is “*”.

For Example

a * b;  10 * 2 = 20

Int main()

{

Int a, b;

a = 10;

b = 4;

cout << “a * b =” << (a * b) <<endl;

}

## Division Operatorin C++

This operator is used to divide the two numbers or variables. The first number is divided by the other. The symbol is used for this operator is “ / ”.

For Example

a / b;  ,  20 / 5 = 4

Int main()

{

Int a, b;

a = 20;

b = 4;

cout << “a / b =” << (a / b) <<endl;

}

## Modulus Operatorin C++

This operator computes the reminder of two values or variables when divided. The symbol of the modulus operator is “%”.

For Example

a % b;    40 % 2 = 0

Int main()

{

Int a, b;

a = 20;

b = 4;

cout << “a % b =” << (a % b) <<endl;

}

File Under: