Page 117 - 6437
P. 117
Structures
Arrays allow to define type of variables that can hold several data items of the same kind.
Similarly, structure is another user-defined data type available in C that allows to combine data
items of different kinds.
Structures are used to represent a record. Suppose you want to keep track of your books in
a library. You might want to track the following attributes about each book:
Title
Author
Subject
Book ID
Defining a Structure
To define a structure, you must use the struct statement. The struct statement defines a
new data type, with more than one member. The format of the struct statement is as follows:
The structure tag is optional and each member definition is a normal variable definition,
such as int i; or float f; or any other valid variable definition. At the end of the structure's
struct [structure tag]
{
member definition;
member definition;
...
member definition;
} [one or more structure variables];
definition, before the final semicolon, you can specify one or more structure variables but it is
optional. Here is the way you would declare the Book structure:
struct Books
{
char title[50];
char author[50];
char subject[100];
120