Hi there,
This is a Prefix vs Postfix problem.
Taking your example of a = 5:
a++ tells the compiler to add 1 to the value within "a" AFTER the line is fully processed.
++a tells the compiler to add 1 to the value within "a" BEFORE the line is fully processed.
If you printf a++, you should get a result of 5.
If you printf ++a, you should get a result of 6.
a++ + a++ + a++ + a++; is all one expression to process in the same line. Since "a" isn't increased until after the the line is processed, then:
(a++ = 5) + (a++ = 5) + (a++ = 5) + (a++ = 5) = 20
Now, in your second expression, since you introduce a "++a" this tells the compiler: first add 1 to "a" and THEN evaluate the entire expression, so this turns out to be:
(a++ = 6) + (a++ = 6) + (++a = 6) + (a++ = 6) = 24.
The compiler basically looks at ++a first and performs that operation and then it looks at the rest of the line and basically does the same thing it did in the previous expression (doesnt change "a" until the line is processed). But since ++a changed it to 6, then 6 is stored in "a".