## INCREMENT AND DECREMENT OPERATOR

INCREMENT AND DECREMENT OPERATOR
C HAS TWO USEFUL OPERATOR INCREMENT (++) AND DECREMENT (- -) These are the unary operator because these operate on only single operand
The increment operator (++) increment the value of the variable by 1 and decrement operator (- -) decrement   the value of the variable by 1 we can write this as –
++a or a=a+1
- - a or a=a-1
These operator   are of two types
1.Prefix increment /decrenment
Here ,first the value of variable is incremented/decremented then the value  of variable is taken for operation.
Ex-
Let us take the value of a =3
Then the statement b=++a ; means first increment the value   of ‘a’ by 1 then ‘b’takes the value of ‘a’
Hence a=4          b=4
The statement b=- -a; ,means first decrement the values of ‘a’ by 1 then ‘b’ tekes   the values of ‘a’
Hence a=3             b=3
/* program to understand   the use of prefix increment /decrement*/
#include<stdio.h>
Void main( )
{
Int a=3;
Printf(“a=%d\n”,a);
Printf(“a= %d\n”,++a)        */prefix increment*/
Printf(“a=%d\n”a);
Printf(“a=\n”,- -a);                 /* prefix decrement*/
Printf(“ a=%d\n”,a);
}
Output:
a=3
a=4
a=4
a=3
a=3
2.postfix increment /decrement
Here , first the value of variable is taken   for operation then value of variable is increment /decremented.
Ex-
a++
a- -
Ex-
Lets us take the value of a=3
Then the statement b=a++ ;means first ‘b’ take   the value of ‘a’ then increment it b y 1.
Hence a=4    b=3
The statement b=a- - means first ‘b’ takes the value of ‘a’ then decrement it by 1.
Hence a=3   b=4
/*program to  understand the use of prefix increment / decrement */
# include<stdio .h>
Void main( )
{
Int a =3;
Printf(“a=%d\n”a);
Printf( “a=%d\n”,a++);/*postfix increment*/
Printf(“a=%d\n”,a);
Printf(“a=%d\n”a- -);
Printf(“a=%d\n”,a);
}
Output:
a=3
a=3
a=4
a=4
a=3

Print | posted on Monday, February 11, 2013 5:35 PM