Array of Structures


It is possible to create an array whose elements are of structure type. Such an array is known as an array of structures. Consider the structure type struct book defined in Program 13. The information about the title of the book, author's name, number of pages and its price can be stored in a variable of type struct book. We have created the variables book1 and book2 of this type in Program 13 to store the specified information about two books. Now, suppose we need to store the information about a number of books available in a library. To store the information about several books, creating a separate variable for each book is not feasible. Here an array of structures provides a convenient way to store the information about the books available in the library. The piece of code in Program 16 illustrates the use of array of structures for this purpose.

Program 16. A program that illustrates the use of array of structures

Post a Comment

Previous Post Next Post