Arithmetic Operators

Arithmetic Operators are those which we use in order to perform mathematical operations.



Following table shows all the arithmetic operators supported by C language.


OperatorsWhat They Do ..Precedence
++Performs Increment (by 1) on Operand1
--Performs Decrement (by 1) on Operand1
*Performs Multiplication on Operands2
/Performs Division on Operands2
%Performs Modulus operation on Operands ,
gives remainder after complete division
2
+Performs Addition on Operands3
-Performs Subtraction on Operands3




Increment (++)

The Increment-Decrement Operators work by adding/subtracting 1 from the number.

They are of 2 types :

  • Pre (++x) : First increments the value and then uses it.
  • Post (x++) : First uses the value then increments it.




  • Syntax:

     ++[variable] or [variable]++


    Example:

    int main()
    
    {
    
      int a=10;
    
      printf("a=%d",a);  //Value in memory and printed : a=10
    
      a++;                      // Value in memory : a=11;
    
      printf("\na=%d",a);   
    
      printf("\na=%d",a++);  // Value 1st  Printed (  a=11 ) then changed in memory...
    
      printf("\na=%d",a);   // Value of a = 12
    
      return 0;
    
    }
    



    Decrement (--)

    The Decrement Operators work by subtracting 1 from the number.

    They are of 2 types :
  • Pre (--x) : First decrements the value and then uses it.
  • Post (x--) : First uses the value then decrements it.




  • Syntax:

      --[variable] or [variable]--



    Example:

    #include<stdio.h>
    
    int main() {
    
    	int a=10;
    
    	printf("a=%d",a);
    
    	//Value in memory and printed : a=10
    
    	a--;
    
    	// Value in memory : a=9;
    
    	printf("\na=%d",a);
    
    	printf("\na=%d",a--);
    
    	// Value 1st  Printed (  a=9 ) then changed in memory...
    
    	printf("\na=%d",a);
    
    	// Value of a = 8 
    
    	return 0;
    
    }