In this C++ tutorial, you shall learn about Addition Assignment operator, its syntax, and how to use this operator, with examples.
C++ Addition Assignment
In C++, Addition Assignment Operator is used to add a value (right operand) to this variable (left operand) and assign the result back to this variable (left operand).
The syntax to add a value of 2
to variable x
and assign the result to x
using Addition Assignment Operator is
x += 2
ADVERTISEMENT
Example
In the following example, we take a variable x
with an initial value of 5
, add a value of 2
to x
and assign the result to x
, using Addition Assignment Operator.
main.cpp
#include <iostream> using namespace std; int main() { int x = 5; x += 2; cout << "x : " << x << endl; }
Output
x : 7 Program ended with exit code: 0
Conclusion
In this C++ Tutorial, we learned about Addition Assignment Operator in C++, with examples.