Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Concerning the assignment operators, the C++ standard says the following (C++03 §5.17/1):</p> <blockquote> <p>There are several assignment operators... <strong>all require a modifiable lvalue as their left operand</strong></p> </blockquote> <p>An array is not a modifiable lvalue.</p> <p>However, assignment to a class type object is defined specially (§5.17/4):</p> <blockquote> <p>Assignment to objects of a class is defined by the copy assignment operator.</p> </blockquote> <p>So, we look to see what the implicitly-declared copy assignment operator for a class does (§12.8/13):</p> <blockquote> <p>The implicitly-defined copy assignment operator for class X performs memberwise assignment of its subobjects. ... Each subobject is assigned in the manner appropriate to its type:<br> ...<br> -- if the subobject is an array, each element is assigned, in the manner appropriate to the element type<br> ...</p> </blockquote> <p>So, for a class type object, arrays are copied correctly. Note that if you provide a user-declared copy assignment operator, you cannot take advantage of this, and you'll have to copy the array element-by-element.</p> <hr> <p>The reasoning is similar in C (C99 §6.5.16/2):</p> <blockquote> <p>An assignment operator shall have a modifiable lvalue as its left operand.</p> </blockquote> <p>And §6.3.2.1/1:</p> <blockquote> <p>A modifiable lvalue is an lvalue that does not have array type... [other constraints follow]</p> </blockquote> <p>In C, assignment is much simpler than in C++ (§6.5.16.1/2):</p> <blockquote> <p>In simple assignment (=), the value of the right operand is converted to the type of the assignment expression and replaces the value stored in the object designated by the left operand.</p> </blockquote> <p>For assignment of struct-type objects, the left and right operands must have the same type, so the value of the right operand is simply copied into the left operand.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload