C
cpptutor2000
Could some C guru please help ? I have:
int x = 20, y = 35;
x = x++ + y++;
y = ++x + ++y;
printf("%d %d\n", x, y);
The answers are 57, 94
I tried reasoning using the standard C semantics that ++x means 'first
increment and then do something else', as copared to x++ which is
'first do something else and then increment'.
So, x = x++ + y++; results in x = (20 + 35) + 1 = 56 and y = 36
and then y = ++x + ++y; results in (56+1) + (36+1) = 57 + 37 = 94
Where is the 57 coming from, for x = x++ + y++;
I am using gcc. Thanks in advance for your helpful hints.
int x = 20, y = 35;
x = x++ + y++;
y = ++x + ++y;
printf("%d %d\n", x, y);
The answers are 57, 94
I tried reasoning using the standard C semantics that ++x means 'first
increment and then do something else', as copared to x++ which is
'first do something else and then increment'.
So, x = x++ + y++; results in x = (20 + 35) + 1 = 56 and y = 36
and then y = ++x + ++y; results in (56+1) + (36+1) = 57 + 37 = 94
Where is the 57 coming from, for x = x++ + y++;
I am using gcc. Thanks in advance for your helpful hints.