|
If x and y have structure type Elephant then statement
x = y;does a bit-by-bit copy of the memory occupied by y into the memory occupied by x. The copy is shallow. Fields that are pointers are copied as pointers; the things that they point to are not copied.
Selectors for structures and arrays can be applied to any expression that has the correct type. For example, if type Elephant is defined by
struct Elephant { int size; const char* name; };and A is an array of Elephants, then A[0].name is the name of the Elephant stored at index 0 in array A, and A[0].name[0] is the first character of that name.
You almost always pass a structure by reference or by pointer.
Passing structures by value has led to many errors in programming assignment submissions.
The standards require you to document every structure type. Include
Declaration
struct Elephant;
allows you to use type Elephant*. You cannot
use type Elephant until its full definition
has occurred.
|