Sunday, 5 December 2010

Increment and Decrement Operators


Increment or decreasing the value of the variable by continuously for sometime c provides special operators ++ and – to do this job. The ++ and – are known as increment and decrement operators.
               There are unary operators and requires only one operand. There are four types of increment and decrement operators.
++ prefix increment
++ postfix increment
       _ _ prefix increment
       _ _ postfix decrement

(2) diff. b/w Pre-increment and Post Increment operators


       Post increment
        Per increment
      1.the value is incremented by one after execution is known as post increment operator
     1.the value is incremented by one before execution is known as pre increment operator
     2.syntax
     Variable/value++
     2.syntax
       ++variable/value
     3.eg int a=2
       a++;
      3.eg: int a=3;
         ++a;


How do you construct an increment statement or decrement statement in C?

There are actually two ways you can do this. One is to use the increment operator ++ and decrement operator - -.
Example:
The statement x++ means to increment the value of x by 1. Likewise, the statement x –” means to decrement the value of x by 1. Another way of writing increment statements is to use the conventional + plus sign or minus sign. In the case of x++, another way to write it is x = x +1?.



You may like the following posts:


2.9 operators and Expressions

No comments:

Post a Comment