Table of Contents
The assignment operator (=) assigns the value of the right operand to the left operand. The left operand must be a modifiable object, such as a variable, while the right operand can be a value, variable, or expression.
The assignment operator copies the computed value of the right-hand side into the left-hand side variable. Any previous value stored in the variable is replaced.
Source Code #
#include <iostream>
int main()
{
int number;
number = 100;
std::cout << "Number: " << number << '\n';
return 0;
}
Output #
Number: 100
Explanation #
- The assignment operator (
=) stores the value of the right operand in the left operand. number = 100;assigns the integer value100to the variablenumber.- Any previous value stored in
numberis replaced by the new value. - The left operand must be a modifiable variable or object.
- The right operand may be a constant, variable, function return value, or expression.
- The assignment operator does not compare values; it performs value assignment.
std::coutdisplays the value stored in the variable.return 0;terminates the program successfully.