New course! Every coder should learn Generative AI!
Try a free lesson+ 1
What is +=
what is the meaning of +=
8 Answers
+ 6
In C++, '+=' means '= + '
exemple :
i+=6; // i=i+6;
i+=1; // i=i+1; i++
If you don't understand ask !
+ 4
same as (variable) = (variable) + (any number).
+ 3
n = n + 1
or
n += 1
They are the exact same thing. People use "+=" because it is shorter.
+ 3
thanks a lot
+ 2
Code 101 but if we logically think how can n = n+1??
+ 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
+ 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
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