What are multiplicative operators in C++?

C++Server Side ProgrammingProgramming

The multiplicative operators are −

  • Multiplication (*)
  • Division (/)
  • Modulus or “remainder from division” (%)

These binary operators have left-to-right associativity. The multiplicative operators take operands of arithmetic sorts. The modulus operator (%) contains a stricter requirement in this its operands should be of integral type.

The multiplication operator yields the result of multiplying the first operand by the second.

The division operator yields the result of dividing the first operand by the second.

The modulus operator yields the remainder given by the subsequent expression, wherever e1 is that the 1st operand and e2 is that the second: e1 – (e1 / e2) * e2, where both operands are of integral types.

example

#include<iostream>
using namespace std;

int main() {
   int a = 4, b = 3, c;
   c = a * b;    // Multiplication
   cout << c << endl;
   
   c = a / b;    // Division. Since both are of int type, result will be floored int.
   cout << c << endl;
   
   c = a % b;    // Modulo
   cout << c << endl;
   return 0;
}

Output

This will give the output −

12
1
1
raja
Published on 16-Feb-2018 10:20:39
Advertisements