Increment and Decrement operators

Increment and decrement operators

In this section I am going to discuss about increment and decrement operators. Both these operator are unary operator. Both of these operators work only with single operand. You might thinking about how much the value of variable will be increment or decrement by these operator?.  While both these operator increment the value of variable by 1 and decrement the value of variable also by 1.

Where increment and decrement operators can be used and where can’t ?

Both of these operator can be used with single variable . They can’t be used with constants and expression.

for example:

In both the above printf statement  the compiler will show error. In first expression 5 is constant and in second  printf( x+y+z ) is expression where x,y,z are different variables.

Therefore I will discuss both of them one by one:

Increment Operator are of two types:

a)Postfix  increment

b)Prefix increment

Postfix  increment:

In this increment operator first the value of variable is used then the value of variable is incremented by one.

Syntax:

For example:

OUTPUT:

In first printf the original value of x is printed.In second printf  the value of x is first printed then it is incremented by one.In third printf the value of x is finally printed after increment.

Prefix Increment :

In this operator first the value of operator is incremented by 1 then it is used.

Syntax:

For example:

OUTPUT:

In the fisrt printf the original value of x is printed. In the second printf the value of variable x is incremented by 1 first then it is used. After second printf the value of x is changed so in third printf statement incremented value of x is printed.

Decrement Operator:

This operator is also divided in two categories:
a)Postfix decrement
b)Prefix decrement

Postfix Decrement:

In this also first the value of variable is decremented first then used.
Syntax:

For example

OUTPUT:

In first printf the original value of x is printed. In the second printf the value  of x is first printed the then decrement.In third printf statement the decremented value of x is printed.

Mi 5(White 32 GB) specifications and features.

Prefix decrement:

In this first the value of variable is decremented first then it is used.

For example:

OUTPUT:

In first printf the value of x is printed. In second printf the value of variable is first decremented then it is printed.In third printf the decremented value of x is printed.
Finally you come to know about increment and decrement operators.

Free online test powered by Quick Solution.

Click here for video tutorials by Quick Solution.

Click here to go program gallery.

 

 

4 thoughts on “Increment and Decrement operators”

  1. Pingback: Hermes Birkin Replica
  2. Pingback: fifa 18 coins
  3. Pingback: Maillot Olympique De Marseille

Leave a Reply