Saturday, August 18, 2012

DIFFICULT PREINCREMENT AND POST INCREMENT LOGICS

Its the logic of

if s=++a + (a=5)++ ;
then s=6+5


check

s=++a + ++a  + a++ + ++a + a++ +(a=5)++ ;
printf("result is=%d",s);

here as a=5 initialised at the time of execution as such only one step execution occurs as such
a++/++a will always represent only the 1st initialised value here 6
and (a=5)++ represents 5

also check

a=a++ + a++ + a++ + ++a +(a=6)++ ;
printf("result is=%d",a);

here, (a=6)++ represent  -> 6
++a all instances represent 7
a++ all instances represent 8




if
a=5
s=++a + ++a + a++ + a++
then s=9+9+5+5

if a=5
a=++a + a++
then a=7 + 6