February 2013 Entries

INCREMENT AND DECREMENT OPERATOR

INCREMENT AND DECREMENT OPERATOR         C HAS TWO USEFUL OPERATOR INCREMENT (++) AND DECREMENT (- -) These are the unary operator because these operate on only single operand      The increment operator (++) increment the value of the variable by 1 and decrement operator (- -) decrement   the value of the variable by 1 we can write this as – ++a or a=a+1 - - a or a=a-1 These operator   are of two types 1.Prefix increment /decrenment  Here ,first the value of variable is incremented/decremented then the value  of variable is taken for operation. Ex-  Let us take the value of a =3 Then the statement b=++a ; means first increment the value   of ‘a’ by 1 then ‘b’takes the value of ‘a’ Hence a=4          b=4  The statement b=- -a; ,means first decrement the values of ‘a’ by 1 then ‘b’ tekes   the values of ‘a’ Hence a=3             b=3  /* program to understand   the use of prefix increment /decrement*/ #include<stdio.h> Void main( ) {  Int a=3; Printf(“a=%d\n”,a); Printf(“a= %d\n”,++a)        */prefix increment*/ Printf(“a=%d\n”a);                   Printf(“a=\n”,- -a);                 /* prefix decrement*/                                                Printf(“ a=%d\n”,a); } Output: a=3 a=4 a=4 a=3 a=3 2.postfix increment /decrement  Here , first the value of variable is taken  ... More

Copyright © Afsana Bano

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski

SimplyRashid.com