You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assignment operators store a value in the object designated by the left operand. There are three kinds of assignment operations:
26
+
Assignment operators store a value in the object designated by the left operand. There are two kinds of assignment operations:
28
27
29
-
1. simple assignment, in which the value of the second operand is stored in the object specified by the first operand. 1. compound assignment, in which an arithmetic, shift, or bitwise operation is performed prior to storing the result.
30
-
1. move assignment (for class types) in which resources are transferred without copying.
28
+
1.*simple assignment*, in which the value of the second operand is stored in the object specified by the first operand.
31
29
30
+
1.*compound assignment*, in which an arithmetic, shift, or bitwise operation is performed prior to storing the result.
32
31
33
-
All assignment operators in the following table except the = and &&= operators are compound assignment operators.
32
+
All assignment operators in the following table except the = operator are compound assignment operators.
34
33
35
34
### Assignment Operators
36
35
@@ -47,7 +46,6 @@ All assignment operators in the following table except the = and &&= operators a
47
46
|**&=**|Obtain the bitwise AND of the first and second operands; store the result in the object specified by the first operand.|
48
47
|**^=**|Obtain the bitwise exclusive OR of the first and second operands; store the result in the object specified by the first operand.|
49
48
|**\|=**|Obtain the bitwise inclusive OR of the first and second operands; store the result in the object specified by the first operand.|
50
-
|**&&=**| Move assignment operator (for class types only). If the second operand is an rvalue, move its resources to the first operand (without copying them). See [Move constructors and move assignment operators](move-constructors-and-move-assignment-operators-cpp.md) for more information.|
51
49
52
50
**Operator Keywords**
53
51
@@ -87,11 +85,11 @@ int main() {
87
85
88
86
## Simple assignment
89
87
90
-
The simple assignment operator (=) causes the value of the second operand to be stored in the object specified by the first operand. If both objects are of arithmetic types, the right operand is converted to the type of the left, prior to storing the value.
88
+
The simple assignment operator (**=**) causes the value of the second operand to be stored in the object specified by the first operand. If both objects are of arithmetic types, the right operand is converted to the type of the left, prior to storing the value.
91
89
92
-
Objects of const and volatile types can be assigned to l-values of types that are just volatile or that are neither const nor volatile.
90
+
Objects of **const** and **volatile** types can be assigned to l-values of types that are just **volatile** or that are neither **const** nor **volatile**.
93
91
94
-
Assignment to objects of class type (struct, union, and class types) is performed by a function named operator=. The default behavior of this operator function is to perform a bitwise copy; however, this behavior can be modified using overloaded operators. (See [Overloaded Operators](../cpp/operator-overloading.md) for more information.)
92
+
Assignment to objects of class type (struct, union, and class types) is performed by a function named `operator=`. The default behavior of this operator function is to perform a bitwise copy; however, this behavior can be modified using overloaded operators. See [Operator overloading](../cpp/operator-overloading.md) for more information. In addition, class types can have *copy assignment* and *move assignment* operators. For more information, see [Copy constructors and copy assignment operators](copy-constructors-and-copy-assignment-operators-cpp.md) and [Move constructors and move assignment operators](move-constructors-and-move-assignment-operators-cpp.md).
95
93
96
94
An object of any unambiguously derived class from a given base class can be assigned to an object of the base class. The reverse is not true because there is an implicit conversion from derived class to base class but not from base class to derived class. For example:
97
95
@@ -148,21 +146,21 @@ B = A;
148
146
149
147
can have one of the following effects:
150
148
151
-
- Call the function operator= for `UserType2`, provided operator= is provided with a `UserType1` argument.
149
+
- Call the function `operator=` for `UserType2`, provided `operator=` is provided with a `UserType1` argument.
152
150
153
151
- Call the explicit conversion function `UserType1::operator UserType2`, if such a function exists.
154
152
155
153
- Call a constructor `UserType2::UserType2`, provided such a constructor exists, that takes a `UserType1` argument and copies the result.
156
154
157
155
## Compound assignment
158
156
159
-
The compound assignment operators, shown in the table in [Assignment Operators](../cpp/assignment-operators.md), are specified in the form *e1*`op`= *e2*, where *e1* is a modifiable l-value not of const type and *e2* is one of the following:
157
+
The compound assignment operators, shown in the table in [Assignment Operators](#assignment-operators), are specified in the form *e1**op*= *e2*, where *e1* is a modifiable l-value not of **const** type and *e2* is one of the following:
160
158
161
159
- An arithmetic type
162
160
163
-
- A pointer, if `op` is + or -
161
+
- A pointer, if *op* is **+** or **-**
164
162
165
-
The *e1*`op`= *e2* form behaves as *e1**= e1*`op`*e2*, but *e1* is evaluated only once.
163
+
The *e1**op*= *e2* form behaves as *e1***=***e1**op**e2*, but *e1* is evaluated only once.
166
164
167
165
Compound assignment to an enumerated type generates an error message. If the left operand is of a pointer type, the right operand must be of a pointer type or it must be a constant expression that evaluates to 0. If the left operand is of an integral type, the right operand must not be of a pointer type.
168
166
@@ -176,4 +174,4 @@ In ANSI C, the result of an assignment expression is not an l-value. Therefore,
176
174
177
175
[Expressions with Binary Operators](../cpp/expressions-with-binary-operators.md)<br/>
178
176
[C++ Built-in Operators, Precedence and Associativity](../cpp/cpp-built-in-operators-precedence-and-associativity.md)<br/>
0 commit comments