Describe about increment (++) and decreament (–) operator.

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++;

Leave a comment