Increment and Decrement Operators

                    These Operators are used to control the loops in an effective method.


1. Increment Operator ( ++ ):

                    The symbol ++ is used for incrementing the value by 1.
                    These are Two types
                    i) ++ identifier;    This is also known as prefix increment.
                    ii) identifier ++;    This is also known as postfix increment.

Eg: 
1)  int a=10;  
     ++a; (or) a++; 
     a=11

2)  int a=10,b; 
     b=++a;
     a=11
     b=11 

3)  int a=10,b; 
     b=a++;
     a=11
     b=10

2. Decrement Operator ( -- ):

                    The symbol -- is used for decrementing the value by 1.
                    These are Two types
                    i) -- identifier;    This is also known as prefix decrement.
                    ii) identifier --;    This is also known as postfix decrement.

Eg: 
1)  int a=10;  
     --a; (or) a--; 
     a=9

2)  int a=10,b; 
     b=--a;
     a=9
     b=9 

3)  int a=10,b; 
     b=a--;
     a=9
     b=10



Next Topic        :  Bit-wise Operators

Previous Topic :  Assignment Operators

No comments:

Post a Comment