Did you put the second example in a small program and run it?
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
>>//Given x=10 and y=5
y = 2*y++ + --x;
y = (2*y++) + (--x)
//substitute, not valid but easier to see
y = (2 * 5++) + (--10);
y = (2 * 5) + (--10) //5++ returns 5 first then increments, so 5 will be multiplied to 2
y = 10 + (--10)
y = 10 + 9 //--10 decrements first then returns so --10 decrements to 9 first
y = 19
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
I wonder if some compilers would actually increment the y during multiplication.
...that seems to violate a math rule, though.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Given i = ++i;
Does ++ changei?
Does = change i?
If the answer is yes to both, undefined.
Why would it be different from i = i++; ?
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944