UMBC CS 201, Spring 02
UMBC CMSC 201 Spring '02 CSEE | 201 | 201 S'02 | lectures | news | help

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 S'02 | lectures | news | help

Thursday, 17-Jan-2002 13:52:08 EST