I was practicing increment operator with its two varieties prefix and postfix. For fun, I wrote the following program which has left me puzzled. The main body of the program is as follows:
int a=10;
a=a++;
cout << a;
The output I got is 10. First I thought it's true, as the assignment is done first and then the value of a is incremented by 1. So yes output should be 10 as it is shown.
But the seconds later I thought it should be 11. Because when the second statement is completed, even though a was assigned to 10, immediately we also incremented it by 1. So the output should be 11. What's going wrong here? Thanks.