rinku jain wrote:
now what happening here is that there is common memory of i
so if I post increment i, assign it to i i.e i=i++
what would be in i will be 22
but after assigning i is incremented i++ i.e actually means i=i+1;
so actually the output should be 23 instead of 22.
Actually, no. Post increment doesn't mean to increment after the expression is completely evaluated. Post increment means to increment the variable after it is used in the expression. Now, whether the increment happens first or whether the assignment happens first depends on the evaluation order. And the order of evaluation requires that the right side be evaluated, and hence, i gets incremented, before the assignment takes place.
Henry