I dont understand where the 1 is coming from. When it gets to this point
i = i++ + f1(i);
i is 1. So if f1 returns 0, should shouldn't i be 2 because of the i++? i.e. the output to be 0,2,2? See comments below
This more or less simplifies to
i = i++;
and we have a FAQ on why that leave i how it was...but basically, assuming i is one before we get to this line
1) we have a post-fix operator, so get the value of i. It is 1. Remember that value for a moment.
2) We now increment i, making it 2.
3) We now assign THE VALUE WE REMEMBERED to i. the value was 1, so assign 1 to i
4) i is now 1.
So for a brief, brief instant, after the increment operator but before the assignment, i IS equal to 2, but we then reset it back to 1.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors