Array of Structures: by creating array type variable to structure data type, we can store multiple records like Employee details, Customer details, Student details, Account details etc.
struct Emp { …. }; | struct Emp e; -> store 1 record struct Emp e1, e2, e3; -> store 3 records struct Emp arr[100]; -> store 100 records |
Program to store multiple records into Array variable of structure type:
#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; } |
