Contents of structs can be assigned, using the assignment operator =, directly to each other, by default invoking memberwise copying. This may mean that two structs are not equal to each other even where one has just been assigned to the other, since alignment of items may lead to undefined values in gaps in the structs.
The declaration of a struct variable (rather than a pointer) causes storage to be allocated on the runtime stack (rather than the heap) to hold its contents. It can be initialised in its declaration by assigning it the contents of another struct. At the end of the block where it is declared, such a struct is automatically deleted.
Structs can be created dynamically using new, in a similar way to arrays. They can also be returned by using delete. This replaces the use of malloc() and free() in ANSI C.
Unions are similar to structs in these respects.
Note that the members of a struct or union are by default publicly accessible, not private or protected, unlike members of classes.
An example of building a linked list in C++.
Next note in series
Back to index