# C – Increment And Decrement

C – Increment And Decrement 2017-08-05T17:58:57+00:00

# Increment and Decrement Operators :

C offers two unusual and unique operators ++  and — called  increment and decrement operator respectively. The use of these two operators will results in the value of the variable being incremented or decremented by unity. i=i+1 can be written as i++ and j=j-1 can be written as j—.

The operators can be place either before or after the operand. If the operator is placed before the variable (++I or –I) it is known as pre incrementing or pre decrementing.

If the operator is placed after the variable (I++ or I–) it is known as post incrementing or post decrementing.

Pre incrementing or pre decrementing or post incrementing or post decrementing have different effect when used in expression. In the pre increment or pre decrement first the value of operand is incremented or decremented then it is assigned.

Example:
x=100;
y=++x;
After the execution the value of y will be 101 and the value of x will be 100.

In the post increment or post decrement first the value of operand is assigned to the concern variable and then the increment or decrement perform.

Example:
x=100;
Y=x++;
After the execution the value of y will be 100 and the value of x will be 101.

C – INCREMENT AND DECREMENT OPERATOR EXAMPLE PROGRAM :

Output :

 Enter the value of x 10 Enter the value of y 20 x = 10 y = 20 x = 11    y  =  21 p = 10    q  = 20 x =  10    y  =  20 p = 10     q  =  20