|
The left-hand operand of an assignment operator must be a nonconst lvalue. Each of these assignments is illegal: - int i, j, ival;
- const int ci = i;
1024 = ival; i + j = ival; ci = ival;
Array names are nonmodifiable lvalues: An array cannot be the target of an assignment. Both the subscript and dereference operators return lvalues. The result of dereference or subscript, when applied to a nonconst array, can be the left-hand operand of an assignment: - int ia[10];
- ia[0] = 0;
- *ia = 0;
The result of an assignment is the left-hand operand; the type of the result is the type of the left-hand operand.
在C++(www.cppentry.com) 中,赋值是一种表达式,其值是(赋完值之后的)左侧操作数,其类型与左侧操作数(也就是被赋值的对象) 相同,其副作用是改变左侧操作数的值。这是本章出现的第一个有副作用的表达式,而前面讲的表达式都不会改变操作数本身(重载之后用于输出的左移表达式除外)。
The value assigned to the left-hand operand ordinarily is the value that is in the right-hand operand. However, assignments where the types of the left and right operands differ may require conversions that might change the value being assigned. In such cases, the value stored in the left-hand operand might differ from the value of the right-hand operand: - ival = 0;
Both these assignments yield values of type int. In the first case the value stored in ival is the same value as in its right-hand operand. In the second case the value stored in ival is different from the right-hand operand.
|