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.
#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 Response to "Overview of C Increment and Decrement Operator with Example"
Post a Comment