Arithmetic Operators in C Programming

C language have a following arithmetic operators. Assume variable i holds 100 and variable j holds 200 then –

Operator Description Example
+ Adds two operands. i + j = 300
Subtracts second operand from the first. i − j = -100
* Multiplies two operands. i * j = 20000
/ Divide. j / i = 2
% Modulus Operator returns the remainder of integer division. j % i = 0
++ Increment operator increases the value of variable by one. i++ = 101
Decrement operator decreases the value of variable by one. i– = 99

Example : Write a program to demonstrate the various arithmetic operators.

#include	
int main() 	
{
    int a=10;
    int b=25;
    int c,d ,e,f;
    c=a+b;		// add value of variable a&b and store in variable c (c=35)
    d=b-a;		// subtract value of variable a from b and store in variable d (d=15)		
    e=b/a;		// e=2	
    f=b%a;		//f=5
   	printf(" value of c= %i", c);
   	printf("\n value of d= %i", d);	
   	printf("\n value of e= %i", e);	
   	printf("\n value of f= %i", f);			
   	return 0;
    
}

OUTPUT

 value of c= 35
 value of d= 15
 value of e= 2
 value of f= 5

Increment and Decrement Operator

  1. Increment operator      ++
  2. Decrement operator    —

In a C language, Increment operator (++)  increases the value of variable by one and Decrement operator  (–) decreases the value of variable by one.

There are two form of increment  and decrement operator:

  1. Prefix form
  2. Postfix form

Prefix Form : In the prefix expression operator appears in the expression before the operands.

Example : ++A 

In the prefix form first the value of operand is increment or decrement than the value of operand is used in expression.

Example
int  i = 10;
j = ++i ;	// j=11 , i=11 
 

Postfix Form: In the postfix expression operator appears in the expression after the operands.

Example : A++

In the postfix form first the value of operand is used in expression than value of operand is incremented or decremented.

int  i = 10;										
j = i++ ;	// j=10, i=11  

Example: Write a program to demonstrate the increment and decrement operator. 

#include
int main()	
{   
    int a=10;
    int b,c;
    b=++a;		// b=11, a=11
    c=a++;   	//c= 11, a=12
    printf(" value of a= %i", a);
    printf("\n value of b= %i", b);
    printf("\n value of c= %i", c);
    return 0;
   }

OUTPUT

value of a= 12
 value of b= 11
 value of c= 11