C Array of Structures

C Array of Structures:

In order to store multiple data of different data types, an array of structures is used.

Example:

#include<stdio.h>  
#include <string.h>
 
struct student 	 
{   
int roll_no; 	 
char name[30]; 	 
};  
 
void main( )    
{  
struct student s[3];
int i;
 
s[0].roll_no = 1;    
strcpy(s[0].name, "Vibhuti Singh");
s[1].roll_no = 2;    
strcpy(s[1].name, "Yashvendra Singh");
s[2].roll_no = 3;    
strcpy(s[2].name, "Pankaj Mittal");
 
for(i=0;i<3;i++)
{    
printf( "Student Enrollment No. : %d\n", s[i].roll_no);    
printf( "Student Name : %s\n\n", s[i].name);    
}
}

Output

Student Enrollment No. : 1
Student Name : Vibhuti Singh
 
Student Enrollment No. : 2
Student Name : Yashvendra Singh
 
Student Enrollment No. : 3
Student Name : Pankaj Mittal