The following of post-increments will result as follows:
n = 1; j = n++; //j = 1, n = 2 j = n++; //j = 2, n = 3 j = n++; //j = 3, n = 4
My question is why the following resulted in n = 1
and not n = 3
?
n = 1; n = n++; //n = 1 n = n++; //n = 1 n = n++; //n = 1
If the code was done with pre-increment of n
(++n
), the result is n = 4
which is to be expected. I know the second code segment should never be done like that in the first place but it is something that I came across and I was curious as to why it resulted like that.
Please advise.