C-Query
Shashidhara S Bapat
ssbapat@ncoretech.com
Wed Sep 15 04:23:00 GMT 2004
Hi All,
I have doubts in the following C program: (I used gcc compiler)
>>>
#include <stdio.h>
int main()
{
int i, j, b;
i = 12, j = 1;
b = ++i + ++i + i++;
printf("%d\n", b);
i = 12, j = 1;
b = j++ + ++j;
printf("%d\n", b);
i = 12, j = 1;
b = ++i + ++i + i++ + j++ + ++j ;
printf("%d\n", b);
return 0;
}
and the output of the code is :
42
4
45.
..and my question is why do we get 42 in the first printf? (I was
expecting 41 (13+14+14) O:-) ) and in the second printf why it isn't 3?
(If it is because of the usage of stack (and/or tree) during the
evaluation of those expressions, why dont we get 46 in the 3rd printf
(42 + 4) ?).
Does it depend on the compiler?
Please let me know abt the reason.
thanks in advance.
--
-Regards,
Shashi.
More information about the Gcc-help
mailing list