ARRAY STRUCTURE
An array of structures is simply an array where each element is a structure.
It allows you to store several structures of the same type in a single array.
Array of Structure Declaration
the array of structure can be defined in a similar way as any other variable.
struct struct_name arr_name [size];
Example
#include <stdio.h>
struct Student {
int roll;
};
int main() {
struct Student s[2] = { {1}, {2} };
printf("%d\n", s[0].roll);
printf("%d\n", s[1].roll);
return 0;
Traversal
#include <stdio.h>
#include <string.h>
// Structure definition
struct Student {
char name[50];
int age;
float marks;
};
int main() {
// Declaration and initialization of an array of structures
struct Student students[3] = {
{"Nikhil", 20, 85.5},
{"Shubham", 22, 90.0},
{"Vivek", 25, 78.0}
};
// Traversing through the array of structures and displaying the data
for (int i = 0; i < 3; i++) {
printf("Student %d:\n", i+1);
printf("Name: %s\n", students[i].name);
printf("Age: %d\n", students[i].age);
printf("Marks: %.2f\n\n", students[i].marks);
}
return 0;