An array of structures is used when you want to store and process a list of records (objects) where each record contains multiple data fields.
Thank you for reading this post, don't forget to subscribe!- For example, to store data for multiple students.
Syntax:
struct StructureName {
data_type member1;
data_type member2;
...
};
struct StructureName arrayName[size];Example:
#include <stdio.h>
struct Student {
int id;
char name[50];
float marks;
};
int main() {
struct Student students[3] = {
{1, "Alice", 85.0},
{2, "Bob", 90.5},
{3, "Charlie", 78.3}
};
for (int i = 0; i < 3; i++) {
printf("ID: %d, Name: %s, Marks: %.2f\n",
students[i].id, students[i].name, students[i].marks);
}
return 0;
}