Ad Code

Responsive Advertisement

increment and decrement.


Unary Operator : Unary operators require only one operand with operator. C allows two very useful operators not generally found in any other languages.



they are ++(increment) and - - (decrement) operator. the operator ++ adds 1 to the operand, and - - subtract 1.both are unary operator and takes the following form.

   ++m and m++
   - - m and m--

we use increment and decrement in for and while loops.



 Example :
 #include<stdio.h>
 void main ()
 { 
      Int y, m=5; 
     y=m++;
     printf("1) y=%d and m=%d", y, m) ;

     y=++m;
    printf("2) y=%d and m=%d", y, m) ;

    y=m--;
    printf("3) y=%d and m=%d", y, m) ;

     y=--m;
     printf("4) y=%d and m=%d", y, m) ;

 }

out put : 1) y=5 and m=6.
                 2) y=6 and m=6.
                3) y=5 and m=4. 
               4) y=4 and m=4. 


 So, it is a unary operators.


❮ Previous                                                      Next ❯

Post a Comment

0 Comments