Google News
logo
Increment and Decrement Operators
In C, “++” and “--“are called increment and decrement operators respectively. Both of these operators are unary operators, i.e., used on single operand. ++ adds 1 to operand and -- subtracts 1 from operand respectively.
  Syntax :
increment operator: ++var_name; (or) var_name++;
Decrement operator: --var_name; (or) var_name--;
  Example :
Let a=5 then      
a++; // becomes 6
a--; //becomes 5
  Program 1 :
#include<stdio.h>
#include<conio.h>
void main( )  {
  int i=1;
  while(i<10) {
   printf(“%d”,i);
  i++;
}
}
Output :

123456789

  Program 2 :
#include<stdio.h>
#include<conio.h>
void main( )  {
  int i=20;
  while(i>10)   {
  printf(“%d”,i);
  i--;
  }
}
Output :

20 19 18 17 16 15 14 13 12 11

Pre increment means adding 1 to the value before assigning it to variable     ex: ++i;

Post increment means adding 1 to the value after assigning it to variable     ex: i++;

Pre decrement means subtracting 1 from the value before assigning it to variable     ex: --i;

Post decrement means subtracting 1 from the value after assigning it to variable     ex: i--;