assignment_expression: conditional_expression prefix_expression assignment_operator assignment_expression assignment_operator: = *= /= %= += -= <<= >>= &= ^= |=
Assignment operators group right-to-left. The target of the assignment must be a modifiable lvalue. The type of the result is the type of the left operand, and the left operand is updated according to the assignment operator that is applied.
If both operands are of arithmetic type, the type of the right operand is converted to match the type of the left operand as required.
The expressions:
A op= B (where op is one of * / % + - << >> & ^ |) A = A op B
behave similarly, except that in the former expression A is evaluated once, whereas in the latter it is evaluated twice. The restrictions that apply to the operands of the above-mentioned counterparts of the assignment operators also apply to the operands of the assignment operators. For example, when the left operand of the operators += and -= is of pointer type, the right operand must be of integral type (see the topic of additive operators).
In the case of operator=, if the left operand is an enumeration, the right operand must be of the same type. In such cases, implicit conversion from integral type to the type of the enumeration is not performed (although casting can be used to explicitly convert an integer to the type of the enumeration).
If the left operand of an assignment is of pointer type, the right operand must be of pointer type or be a constant expression that evaluates to zero. The right operand is converted to the type of the left as required.
For a given type T, it is illegal to attempt to assign:
Assignments in the opposite direction are possible for all of the above-mentioned cases. For further information see the topics of pointers and syntax in the declarators subsection of the chapter on declarations .
If the left operand of an assignment is of type pointer to member, the right operand must be of type pointer to member or be a constant expression that evaluates to zero. The right operand is converted to the type of the left as required.
Given a class D that unambiguously and publicly derives from a class B (directly or indirectly), a pointer to a member of B may be converted to a pointer to a member of D, provided that the member that is pointed to is of the same type in both cases.
An object of type T may be assigned to an object of type reference to T (i.e. type T&). Upon performing such an assignment, the object that is referenced is updated.
The assignment of one instance of a class C to another, results in the class assignment operator being called. An assignment operator for the class is typically of one of the forms:
C& C::operator=(C&) or C& C::operator=(const C&).
If the application does not define an assignment operator for the class then a default assignment operator is used. Note that an instance of a class that unambiguously and publicly derives from C can be assigned to C.
Initialization and assignment of classes are two different operations !