Array of Structures in C Programming
Array of Structures in C Programming
Introduction to Array of Structures in C Programming
An array of structures in C programming is used to store multiple records of the same structure type. It allows you to manage a group of related data efficiently.
Array of structures in C programming is commonly used in applications like student records, employee data, and database-like storage.
What is Array of Structures
An array of structures is a collection of structure variables stored in a single array.
Syntax
Example
Define Structure and Array
struct Student {
int id;
char name[20];
float marks;
};
int main() {
struct Student s[3];
return 0;
}
Input Data in Array of Structures
struct Student {
int id;
char name[20];
float marks;
};
int main() {
struct Student s[2];
for(int i = 0; i < 2; i++) {
printf(“Enter ID: “);
scanf(“%d”, &s[i].id);
printf(“Enter Name: “);
scanf(“%s”, s[i].name);
printf(“Enter Marks: “);
scanf(“%f”, &s[i].marks);
}
return 0;
}
Display Data from Array of Structures
struct Student {
int id;
char name[20];
float marks;
};
int main() {
struct Student s[2];
for(int i = 0; i < 2; i++) {
printf(“Enter ID: “);
scanf(“%d”, &s[i].id);
printf(“Enter Name: “);
scanf(“%s”, s[i].name);
printf(“Enter Marks: “);
scanf(“%f”, &s[i].marks);
}
printf(“\nStudent Details:\n”);
for(int i = 0; i < 2; i++) {
printf(“ID: %d\n”, s[i].id);
printf(“Name: %s\n”, s[i].name);
printf(“Marks: %.2f\n”, s[i].marks);
}
return 0;
}
Example: Find Highest Marks
struct Student {
int id;
float marks;
};
int main() {
struct Student s[3] = {
{1, 85.5},
{2, 90.0},
{3, 78.5}
};
int i, index = 0;
for(i = 1; i < 3; i++) {
if(s[i].marks > s[index].marks) {
index = i;
}
}
printf(“Topper ID: %d\n”, s[index].id);
printf(“Highest Marks: %.2f”, s[index].marks);
return 0;
}
Advantages of Array of Structures
Key Benefits
- Store multiple records efficiently
- Easy data management
- Works well with loops
- Useful in real-world applications
Common Use Cases
Where It is Used
- Student management system
- Employee records
- Inventory systems
- Database-like storage
Start Learning C Programming
Practice array of structures programs to manage complex data effectively.
Summary
Array of structures in C programming allows storing multiple records of structured data. It is widely used for handling grouped data.
FAQs
What is array of structures in C programming?
It is a collection of structure variables stored in an array.
Why use array of structures?
To store multiple records efficiently.
How to access elements?
Using index and dot operator.
Can we use loops with structures?
Yes, for input and output.



