3.1.Arithmetic Operators

What is an arithmetic operator?

An arithmetic operator is an calculate operator like: Add, Subtract, Multiply, Divide, Modulus, and Increase of Decrease operator.

There are following arithmetic operators supported by C++ language

Example 1: Declaration variable for follow operator bellow

int A=10, B=20;

Operator Description Example
+  Adds two operands  A + B will give 30
 Subtracts second operand from the first  A – B will give -10
*  Multiplies both operands  A * B will give 200
/  Divides numerator by de-numerator  B / A will give 2
%  Modulus Operator and remainder of after an integer division  B % A will give 0
++  Increment operator, increases integer value by one  A++ will give 11
 Decrement operator, decreases integer value by one  A– will give 9

Example 2: Using variable with operator and display the result

 #include<iostream.h>
 #include<conio.h>
 void main()
 {
      int a=10,b=20,result;
      result=a+b;
      cout<<"Result 1: " <<result<<endl;
      result=a-b;
      cout<<"Result 2: " <<result<<endl;
      result=a*b;
      cout<<"Result 3: " <<result<<endl;
      result=a/b;
      cout<<"Result 4: " <<result<<endl;
      result=a%b;
      cout<<"Result 5: " <<result<<endl;
      result=a++;
      cout<<"Result 6: " <<result<<endl;
      result=b--;
      cout<<"Result 7: " <<result<<endl;
      getch();
 }

Suggest Edit