What is the difference between a += b and a =+ b , also a++ and ++a?

a += b is equivalent to a = a + b

a = +b is equivalent to a = b

a++ and ++a both increment a by 1.
The difference is that a++ returns the value of a before the increment whereas ++a returns the value after the increment.

That is:

a = 10;
b = ++a; //a = 11, b = 11

a = 10;
b = a++; //a = 11, b = 10

Leave a Comment