Array of Structures in C

There can be array of structures in C programming to store many information of different data types. The array of structures is also known as collection of structures.

Let’s see an example of structure with array that stores information of 5 students and prints it.

  • #include<stdio.h>  
  • #include <string.h>    
  • struct student{    
  • int rollno;    
  • char name[10];    
  • };    
  • int main(){    
  • int i;    
  • struct student st[5];    
  • printf(“Enter Records of 5 students”);    
  • for(i=0;i<5;i++){    
  • printf(“\nEnter Rollno:”);    
  • scanf(“%d”,&st[i].rollno);    
  • printf(“\nEnter Name:”);    
  • scanf(“%s”,&st[i].name);    
  • }    
  • printf(“\nStudent Information List:”);    
  • for(i=0;i<5;i++){    
  • printf(“\nRollno:%d, Name:%s”,st[i].rollno,st[i].name);    
  • }    
  •    return 0;    
  • }    


Enter Records of 5 students
Enter Rollno:1
Enter Name:Abhishek
Enter Rollno:2
Enter Name:Naman
Enter Rollno:3
Enter Name:Vinu
Enter Rollno:4
Enter Name:Bruce
Enter Rollno:5
Enter Name:Bhagat

Student Information List:
Rollno:1, Name:Abhishek
Rollno:2, Name:Naman
Rollno:3, Name:Vinu
Rollno:4, Name:Bruce
Rollno:5, Name:Bhagat