PAUSE
ENCORE5
ENCORE
BOX
ILLUSTRATION
GO
A structure is primarily used for holding
related variables of differing types in one group.
If, for example, we want to keep information on a ski racer,
we'd want to include the racer's name, her or his country,
event, and the best time on the course.
Let us build the structure skier!
struct skier {
The first variable is the name which
is a string of 20 characters, + a NULL character!
(see diagram above)
char name[21];
1234567890123456789012345
char name[21];
The second variable is the country which
is a string of 10 characters, + a NULL character!
char country[11];
char country[11];
The third variable is the event which is an integer.
int event;
int event;
The forth variable is the speed which is a float.
float speed;
};
float speed;
Therefore, the space allocated for the structure is at least as
big as the space required by all the structure elements combined!