Array of Structures in C

In C Programming, Structures are used to group different data types to organize the data in structural way and Arrays are used to group same data type values. In this article we will show you the Array of Structures in C concept with one practical example.

For example, we are storing employee details such as name, id, age, address and salary. Normally we group them as employee structure with the above mentioned members. We can create the structure variable to access or modify the structure members. A company may have 10 to 100 employee, how about storing the same for 100 employees?

In C Programming, We can easily solve the above mentioned problem by combining 2 powerful concepts Arrays and Structures in C. We can create the employee structure with the above mentioned members and then instead of creating the structure variable, we create the array of structure variable.

Here, Employee structure is used for storing the employee details such as age, name and salary. We created the array of structures variable Employees [4] (with size 4) at the declaration time only. We also initialized the values of each and every structure member for all the 4 employees.

Within this Array of Structures in C example, We declared the student structure with Student Name, C Marks, Data Base Marks, C++ Marks and English Marks members of different data types.

Within the main() function we created the array of structures student variable and initialized the appropriate values to the structure members

In the Next line we have For Loop in C Programming Condition inside the for loop will control the compiler not to exceed the array limit. Below printf statements will print the values inside the student structure array.