Nested Structures
Since structure members are variables, and variables can be used in structures,
it is possible to nest structures -- use a structure as a member of another
structure -- a structure within a structure.
For example, a line can be represented by it's end points.
y
| endPoint
| /
| /
| /
| /
| /
| /
| startPoint
|
|
---------------------------- x
struct point
{
int x; /* x-coordinate */
int y; /* y-coordinate */
};
struct line
{
struct point startPoint;
struct point endPoint;
};
If we declare diagonal as
struct line diagonal;
then diagonal.endPoint.x refers to the x-coorindate of
the endPoint member of line