Blogger templates

Pages

Sunday, 22 April 2012

Overview of C Increment and Decrement Operator with Example

Increment operator
Increment operator:
  • var ++ => Indicates post increment. That is use the value of var first and then increment.
  • ++ var => indicates pre increment.That is the value of var must be incremented before it is used. 
 Example:
 
#include<stdio.h>
void main()
{
int x , y;
x=5;
y=10;
printf(" x=%d\n, x++");
printf(" y=%d\n, ++y");
}

Output:
  x=5
  y=11


Decrement operator:
  • --var => indicates decrement the value of var first and then use it.
  • var-- => indicates use the value of var first and then decrement it.
Example:
#include<stdio.h>
void main()
{
int x , y;
x=5;
y=10;
printf(" x=%d\n, --x");
printf(" y=%d\n, y--");

Output:
  x=4
  y=10



0 comments:

Post a Comment