C-Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux