C Programming Tutorial
Computer Tutorial

Arrays of Structures

Arrays of Structures

Structures are often arrayed. To declare an array of structures, you must first define a structure and then declare an array variable of that type. For example, to declare a 100-element array of structures of type addr defined as :

struct addr addr_list[100];

This creates 100 sets of variables that are organized as defined in the structure addr. To access a specific structure, index the array name. For example, to print the ZIP code of structure 3 :
printf("%lu", addr_list[2].zip);

Like all array variables, arrays of structures begin indexing at 0.