Next: Unions Up: Structures Previous: Structures

Defining New Data Types

typedef can also be used with structures. The following creates a new type agun which is of type struct gun and can be initialised as usual:

Here gun still acts as a tag to the struct and is optional. Indeed since we have defined a new data type it is not really of much use,

agun is the new data type. arnies is a variable of type agun which is a structure.

C also allows arrays of structures:

This gives arniesguns a 1000 guns. This may be used in the following way:

gives Arnie's gun number 50 a calibre of, and:

assigns the calibre of Arnie's first gun to itscalibre.
Fri May 20 13:40:49 BST 1994