Arrays of Structures

For Complete YouTube Video: Click Here

In this class, we will understand Arrays of Structures.

We have already discussed the concepts of Arrays and Structures.

Table of Contents

Arrays of Structures

Example

We try to understand the concept of Arrays of Structures by using the example as shown below.

Arrays of Structures Example 1
Example 1

In the above example, we have created the structure to store the details of the student.

We have also created the structure variable stu1 and stu2.

For example, if we want to store the details of hundred students.

We have to create hundred such variables.

Creating hundred such variables is complicated and causes a lot of confusion.

Another possibility to store the details of a hundred students is by creating an array of structures.

The declaration to create a structure of hundred students is as follows.

Arrays of Structures Example 2
Example 2

The image below is the visualization of the array of structures for the student details.

Arrays of Structures Visualization
Visualization

With such kinds of declarations, it is simple and easy to create and access the details of the students.

For example, printf(“%s”, stu[54].name); we can print the name of the 54th student.