The following subsequent increments will look like this:
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 led to n = 1, rather than n = 3?
n = 1;
n = n++; //n = 1
n = n++; //n = 1
n = n++; //n = 1
If the code was executed with a preliminary increment n( ++n), the result will be n = 4what should be expected. I know that the second segment of code should never be done as it was in the first place, but this is what I came across, and I was curious why this happened.
Please inform.
source
share