What is += | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is +=

what is the meaning of +=

4th Jul 2017, 6:45 PM
sandeep kumar
sandeep kumar - avatar
8 Answers
+ 6
In C++, '+=' means '= + ' exemple : i+=6; // i=i+6; i+=1; // i=i+1; i++ If you don't understand ask !
4th Jul 2017, 6:52 PM
Jojo
+ 4
same as (variable) = (variable) + (any number).
9th Jul 2017, 10:57 PM
A_Coders
A_Coders - avatar
+ 3
n = n + 1 or n += 1 They are the exact same thing. People use "+=" because it is shorter.
4th Jul 2017, 7:39 PM
Code101
Code101 - avatar
+ 3
thanks a lot
7th Jul 2017, 5:52 PM
sandeep kumar
sandeep kumar - avatar
+ 2
Code 101 but if we logically think how can n = n+1??
7th Jul 2017, 5:42 PM
sandeep kumar
sandeep kumar - avatar
+ 1
In C++, the '=' operator isn't the same as maths... In maths, 5=4+1 is true. In C++ we have to use '==' In C++, we'll do 5==4+1; // return true '=' MODIFY the value, '==' only "READ" the value
7th Jul 2017, 5:51 PM
Jojo
+ 1
it's called a combinational assignment operator. It's used as a shortcut for Assigning the new value of a variable after an operation. If a=6 b=4 c =2 a+=c //a= a + c b-=a // b= b - a b *=c // b= b * c a/=c // a= a/c
16th Feb 2018, 1:53 PM
Phillip Anekwe 🇳🇬⚡
Phillip Anekwe 🇳🇬⚡ - avatar
0
People are always trying to code using less characters, so in several languages, including JavaScript and C++ you can use the operator than equals to perform that operation and store that as the new value for the variable. a = 1; b = 2; c = 3; d= 4; a += b; // now a = 3; c %= a; // now c = 0; d *= b; // now d = 8; d /= a; // d = 2 because C++ only takes the integer part of the result // So now a = 3, b= 2, c= 0, and d = 2. You could imagine how useful these could be in simulations
12th Jul 2017, 1:49 AM
Chris Foraste
Chris Foraste - avatar