Arrays of Structures

Learn to create arrays of custom data types using structures.

Introduction

Let’s extend the previous book example by adding the structure for a bookstore. A bookstore contains information such as an address, start and end hours, a list of books, and the number of books inside the store.

Recall that we define a book as follows:

typedef struct 
{
    char name[32];
    char author[64];
    char publisher[32];
    int releaseYear;
    int numberOfPages;
} TBook;

To create an array of books, we can write TBook booksList[1024]. The booksList array now contains 1,024 books. Each element booksList[i] is a structure of type TBook. We can access its members like booksList[i].name, booksList[i].author and so on.

See the following memory drawing:

Get hands-on with 1400+ tech skills courses.