Google News
logo
CPP - Interview Questions
What are the various Arithmetic Operators in C++?
C++ supports the following arithmetic operators :
 
+ addition
subtraction
* multiplication
/ division
% module

Let’s demonstrate the various arithmetic operators with the following piece of code.
 
Example :
#include <iostream>
using namespace std;

int main() {
    int a, b;
    a = 4;
    b = 5;

    // printing the sum of a and b
    cout << "a + b = " << (a + b) << endl;

    // printing the difference of a and b
    cout << "a - b = " << (a - b) << endl;

    // printing the product of a and b
    cout << "a * b = " << (a * b) << endl;

    // printing the division of a by b
    cout << "a / b = " << (a / b) << endl;

    // printing the modulo of a by b
    cout << "a % b = " << (a % b) << endl;

    return 0;
}
Output :
a + b = 9
a - b = -1
a * b = 20
a / b = 0
a % b = 4
Advertisement