+ 1

Total += number;

what is the meaning of "+=" ? how it works?

3rd Mar 2017, 11:23 PM
Pietro
3 Answers
+ 14
x += 2 is the same as x = x + 2 You can also you -=, *=, /= It's just faster to type and easier to read.
4th Mar 2017, 12:39 AM
Wiola
Wiola - avatar
+ 3
It serves to reduce the code and avoid redundant. ex. i += 5; it's equal to i = i + 5;
3rd Mar 2017, 11:55 PM
AtoMX
AtoMX - avatar
+ 3
The basic assignment operator is "=". Whereas the the above mentioned assignment operator is shorthand assignment operator. Let us assume two operands "a" and "b". Let us see the actual working of this operator some module. Let "a+=b" be the actual task to be performed. It is equivalent to a=a+b. That is the two operand "a","b" gets added and stored in "a" operand. Similarly "a-=b" implies a=a-b, //Subtraction assignment operator "a*=b" implies a=a*b, //Multiplication assignment operator "a/=b" implies a=a/b, //Division assignment operator "a^=b" implies a=a^b, // Bitwise XOR assignment operator and so on.
4th Mar 2017, 2:20 AM
Buddy
Buddy - avatar