UMBC CS 201, Fall 00
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 endPoint;
struct point startPoint;
};
If we declare diagonal as
struct line diagonal;
then diagonal.endPoint.x refers to the x-coorindate of
the endPoint member of line
CSEE
|
201
|
201 F'00
|
lectures
|
news
|
help
Tuesday, 10-Oct-2000 21:47:20 EDT