Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=) in C++

Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=,
^=, |=)

When we want to modify the value of a variable by performing an operation on the value currently stored in that
variable we can use compound assignment operators:
expression is equivalent to
value += increase; value = value + increase;
a -= 5; a = a - 5;
a /= b; a = a / b;
price *= units + 1; price = price * (units + 1);
and the same for all other operators.

 For example:
// compound assignment operators
#include <iostream>
using namespace std;
int main ()
{
int a, b=3;
a = b;
a+=2; // equivalent to a=a+2
cout << a;
return 0;
}
output : 5


Learn More :