Skip to content Skip to sidebar Skip to footer

Arithmetic Operator in C++

Arithmetic operators are one of the most basic and used operators anywhere in the program in the programming journey, irrespective of the language. They are used to perform arithmetic operations within the programming language.

Arithmetic operators are simply the mathematical operations performed using the programming language to implement in our code. They are binary as they need two values to give an output.

Types of Arithmetic Operators

Here’s the table describing the Arithmetic Operators.

NameSymbolDescription Example
Addition +Adds two/more operands*8 + 9 = 17
SubtractionSubtracts two/more operands*19 – 8 = 11
Multiplication*Multiplies two/more operands*12*12 = 144
Division/Divides two/more operands*125/5 = 25
Modulus%Evaluates the Remainder of two Operands*100%2 = 0
*A variable or a value involved in an operation is called an operand. 

 

Addition

The addition operator adds two or more operands as a result. It’s pretty self-explanatory as it is the fundamental operation of arithmetic mathematics.

Syntax

+

Example

#include <iostream>
using namespace std;

int main()
{
    // By Using Variables

    int a = 10;
    int b = 25;
    int c = a + b;

    cout << c << endl;

    // By Directly adding to output

    cout << 45 + 10 << endl;

    return 0;
}

Output

35
55

Subtraction

The subtraction operator subtracts two or more operands as a result. It’s pretty self-explanatory as it is also the fundamental operation of arithmetic mathematics.

Syntax

-

Example

#include <iostream>
using namespace std;

int main()
{
    // By Using Variables

    int a = 40;
    int b = 25;
    int c = a - b;

    cout << c << endl;

    // By Directly adding to output

    cout << 75 - 10 << endl;

    return 0;
}

Output

15
65

Multiplication

The Multiplication operator multiplies two or more operands as a result. It’s pretty self-explanatory as it is also the fundamental operation of arithmetic mathematics.

Syntax

*

Example

#include <iostream>
using namespace std;

int main()
{
    // By Using Variables

    int a = 40;
    int b = 10;
    int c = a * b;

    cout << c << endl;

    // By Directly adding to output

    cout << 75 * 15 << endl;

    return 0;
}

Output

400
1125

Division

The Division operator divides two or more operands as a result. It’s pretty self-explanatory as it is also the fundamental operation of arithmetic mathematics.

Syntax

/

Example

#include <iostream>
using namespace std;

int main()
{
    // By Using Variables

    int a = 40;
    int b = 10;
    int c = a / b;

    cout << c << endl;

    // By Directly adding to output

    cout << 75 / 15 << endl;

    return 0;
}

Output

4
5

Modulus

The Modulus operator could be something new for you, but it’s effortless. The modulus operator evaluates the remainder from the division of two numbers. Let me explain to you in detail via cases.

Explanation

Case 1

Suppose two integer numbers where a = 10 and b = 2.

We know that a/b (10/2) = 5; therefore, 10 is completely divisible by 2 by providing the remainder of 0.

Hence a%b will give 0. We can also conclude that wherever the number (a) is completely divisible by the divisor (b), the remainder (a%b) will always be zero.

Case 2

Suppose two integer numbers where a = 19 and b = 7.

We know that a/b (19/7) is not completely divisible by 7; hence it will divide at 2 providing the remainder of 5.

Hence a%b will give 5.

So this is how the modulus operator works.

Syntax

%

Example

#include <iostream>
using namespace std;

int main()
{
    // By Using Variables

    int a = 10;
    int b = 2;
    int c = a % b;

    cout << c << endl;

    // By Directly adding to output

    cout << 19 % 7 << endl;

    return 0;
}

Output

0
5

Conclusion

The Arithmetic Operators were just the basics; we’ve got even more types of operators that will help us to program and control the program in the right direction and the way we truly want. Until then, keep learning the basics. Keep Shaping up!

You must also know that GeekonPeak has just begun and is looking for some loyal supporters so we, the new-gen geeky friends, can grow and create more comprehensive and easy-to-grasp courses for you (for free). Follow us on FacebookInstagram & Twitter as well. Also, don’t miss our newsletter subscription. We provide exclusive blogs, tips, tricks, and advice to program efficiently and market smartly. We also promote some of our partners with excellent experiences to share with you. Until next time 🙂

Leave a comment

Sign Up to Our Newsletter

Be the first to know the latest updates