Monday 29 February 2016

Increment and Decrement operators


                                                Increment operators (++)


  • Increment operators are increase the value of subsequent. value may be increase according to the programmer.
  • Increment operator are two types as follows :
    1. Post increment
    2. Pre increment


                  Decrement operators ( -- )


  • decrement operators decrease the value to one, two and so on.
  • As like Increment operators, decrement operators are also two type as :  
    1. Post decrement
    2. Pre decrement
Before we more discuss about increment and decrement operator, let understand some expression; that's are using in all operators.

Now some issues of pre and post increment and decrement, we will discuss after solve following programming :



Now some issues of pre and post increment and decrement, we will discuss after solve following programming :

 x = 5       x = 5     x = 5  
 x = x+1      ++x       x++     
 x = 6       x = 6      x=5   


In above program u notice that value of x increase to one in all three expression but after the increasing one, the final value of x in not same, third box result is differ to another two boxes. Now you know that c operators are mostly three types, ++ and -- operators are Unary operators.

Post increment or decrement are lowest precedence so it is solve at the end of program. Hence above program in third box first value of x is print i.e. 5 after, it is increase.

Unary operators are solve right to left.     

No comments:

Post a Comment

Ads Inside Post