QUOTE(selloorhari @ 7 Feb, 2008 - 04:22 AM)

QUOTE(shreshth91 @ 7 Feb, 2008 - 03:35 AM)

QUOTE(selloorhari @ 7 Feb, 2008 - 03:26 AM)

What is the out put of the following program ?
main ()
{
int a , b ;
a= 5 ;
b = ++a + ++ a + ++a ;
printf("%d",
;
a = 5 ;
b = a++ + a++ +a++ ;
printf ( "%d",b ) ;
}
First one has pre-increments, so it's equivalent to 6+7+8 = 21
And the second will be 5+6+7 = 18 since it has post-increments
But i got 24 as the first O/P
and 15 as the second OP
How is it?
That must mean that your compiler is first incrementing all the values and then displaying in the pre-increment one (8+8+8=24)
And in the post-increment one, it's first displaying and then incrementing all the values (5+5+5=15, final value of a is 8)
This must differ from compiler to compiler. Turbo-C++ shows 21 and 18, and Bloodshed Dev-C++ shows 22 and 15 (22 because of some complications arising due to multiple '+' signs being taken as multiple increment operators; fixed that using a loop to increment).
Just out of curiosity, what IDE were you using?
This post has been edited by shreshth91: 7 Feb, 2008 - 05:34 AM