Array of Structures:
- Using structure variable we can store only one record.
- To store multiple records, we need to declare Array variable of structure type.
- We use loop to process elements of these records.
struct Emp
{
....
....
};
struct Emp e; -> can store only 1 record
struct Emp e1, e2, e3; -> can store upto 3 records
struct Emp arr[100]; -> can store 100 records
#include<stdio.h>
struct Emp
{
int id;
char name[20];
float salary;
};
int main()
{
struct Emp arr[3];
int i;
printf("Enter 3 Emp records : \n");
for(i=0 ; i<3 ; i++)
{
printf("Enter Emp-%d details : \n", i+1);
scanf("%d%s%f", &arr[i].id, arr[i].name, &arr[i].salary);
}
printf("Employee details are : \n");
for(i=0 ; i<3 ; i++)
{
printf("%d \t %s \t %f \n", arr[i].id, arr[i].name, arr[i].salary);
}
return 0;
}