Re: Could you please explain this code segment

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

 



On 12/17/09, W.H. Kalpa Pathum <callkalpa@xxxxxxxxx> wrote:
> 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);

The program evaluates the arguments first and calls
printf then.

You can't do such things if you want to rely on the result, because
the order of the arguments evaluation is implementation-specific (to
begin with).

[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