4.4. Assignment Operators
The left-hand operand of an assignment operator must be a modifiable lvalue. For example, given
int i = 0, j = 0, k = 0; // initializations, not assignmentconst int ci = i; // initialization, not assignment
Each of these assignments is illegal:
1024 = k; // error: literals are rvaluesi + j = k; // error: arithmetic expressions are rvaluesci = k; // error: ci is a const (nonmodifiable) lvalue
The result of an assignment is its left-hand operand, which is an lvalue. The type of the result is the type of the left-hand operand. If the types of the left and right operands differ, the right-hand operand is converted to the type of the left:
k = 0; // result: type int, value 0k = 3.14159; // ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access