UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | 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 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


CSEE | 201 | 201 F'06 | lectures | news | help

Tuesday, 22-Aug-2006 07:14:09 EDT