The difference between += and =+

a += b is short-hand for a = a + b (though note that the expression a will only be evaluated once.)

a =+ b is a = (+b), i.e. assigning the unary + of b to a.

Examples:

int a = 15;
int b = -5;

a += b; // a is now 10
a =+ b; // a is now -5

Leave a Comment

tech