Morris Keesan
9/10/2011 9:16:00 PM
On Sat, 10 Sep 2011 16:31:33 -0400, arni <arnmin@gmail.com> wrote:
> On Sep 10, 10:36Â pm, Mazen <neuroha...@gmail.com> wrote:
>> Hello,
>>
>> Following is a simple program:
>>
>> #include <stdio.h>
>>
>> int main(void) {
>> Â int i = 0, j, k;
>> Â j = k = 2;
>>
>> Â printf("%d %d\n", i=+j, i=-j);
>>
>> Â return 0;
>>
>> }
>>
>> The output is
>> 2 2
>>
>> Shouldn't the second expression be -2 rather than 2? I'm confused.
>> Your insights pls. Thanks!
>
> Shouldn't it be i+=j and i-=j?.. Then you'll get 2 -2.
No. If modifying i twice in the argument list weren't undefined,
so that one assignment to i and the evaluation of the corresponding
function argument were guaranteed to be complete before the next
argument was evaluated, printf("%d %d\n", i += j, i -= j) would produce
either "2 0" or "0 -2", depending on the order in which the arguments
are evaluated, which is unspecified (not undefined). The poorly-spaced
code seems to have been intended as printf("%d %d\n", i = +j, i = -j);
--
Morris Keesan -- mkeesan@post.harvard.edu