posted 22 years ago
I having a problem understanding pre and post operators. I can understand the following simple code:
still results 0 because it is increment after it is assigned to i. But take a look at this more complex version:
every way I look at it, i keep getting different answers! How does one work out the results for this kind of question?
To me I would have thought that starting from the left, it would first (++n) to get a three, then n++ still leaves it three because it is added after, then --n to 2, and again --n to get one, finally incrementing the earlier post operator n++ to get a four (because it was 3 at that point). Finally add all the results, 3+4+2+1 = 10, but the answer is 11?
Any help would be gratefully appreciated, especially any rules of how it works.
Also, how does one KNOW when the object is garbaged collected at a certain point?
Thanks!