Comma Operator
Andrew Koenig
ark at alice.UUCP
Sun Jan 15 05:55:25 AEST 1989
In article <922 at quintus.UUCP>, nair at quintus writes:
> What should this print?
>
> int x, y;
> printf("%d %d\n", (x = 1, y = 2), x, y);
Whatever the compiler wants to print.
> Shouldn't it be equivalent to:
>
> int a, x, y;
> a = (x = 1, y = 2);
> printf("%d %d %d\n", a, x, y);
No.
The arguments of printf are not required to be evaluated
in any particular sequence.
> Is there God? Why am I here? :-) :-)
The first question is too difficult for comp.lang.c
The second can be divided into two parts.
Part 1: `Why?' This is an extremely difficult question as well,
so it is left as an exercise for the reader.
Part 2: `Am I here?' Answer: yes.
--
--Andrew Koenig
ark at europa.att.com
More information about the Comp.lang.c
mailing list