When it comes to pre-increment and post-increment statements, always remember that they apply immediately before / after the variable in question has been read, and before processing the left side or assignment.
eg.
int a = 2; a = a++ + a++ + a++;
a will be equal to 9, since it ends with a = 2 + 3 + 4 ;
Similarly
int a = 2; a = a++;
a will still be 2 , since the assignment occurs after the increment, and the increment occurs after reading .
int a = 2; a = ++a;
a will be 3, since the assignment occurs after the increment , but the increment occurs before reading .
In your second example, the post-increment occurs after reading, and therefore the increment B never has the ability to be read (not used again in the expression) before the assignment (assignment that overwrites B and any effect on the subsequent increment would be).
If you do:
int B = 6; int C = B + B++;
Then you get B equal to 7, and C will be 12. While B++ + B or B + ++B both will have C equal to 13 and B still equal to 7.
Trevor freeman
source share