Could you please explain this code segment

W.H. Kalpa Pathum callkalpa@gmail.com
Thu Dec 17 08:22:00 GMT 2009


The following block of code when compiled with gcc (gcc version 4.4.2
20091027 (Red Hat 4.4.2-7) (GCC) ) resulted in the following output.
Could you please explain how the output differs (when assigned to the
variable b and in printf statement) and the way the compiler executes
each segment of the variable?

int main(){
int a = 10;
int b = (++a) + (++a);
printf("%d %d %d %d\n", b, a++, a, ++a);
printf("%d %d %d %d\n", ++a + ++a, a++, a, ++a);
return 0;
}

OUTPUT
24 13 14 14
36 15 18 18

--
W.H.Kalpa Pathum
http://kalpapathum.blogspot.com
http://thiraya.wordpress.com



More information about the Gcc-help mailing list