Most of the standard operators, like mathematical operators ( +, %, -, etc...), comparison operators (==, >, etc...), and stream operators (<<, >>), do not work on structures. It is possible to define those operators (covered in ChapterΒ 20), but the operators will not work until we do so.
One operator that does work βout of the boxβ for structures is the assignment operator. It can be used in two ways: to initialize the instance variables of a structure from a list of values or to copy the instance variables from one structure to another. An initialization looks like this:
The values in curly braces get assigned to the instance variables of the structure one by one, in order. So in this case, x gets the first value and y gets the second.
It is important to note that an assignment makes a copy of a struct. Once the assignment has been made, changing one struct has no effect on the other. This Codelens demonstrates by coping a struct and then changing one of the copies.