Array of structures in c

with structures, we can store only one particular object but with arrays, we can store multiple structures with a sequence. The structure contains different datatypes compiler treats in a single datatype because they are hidden in the structure.

syntax:

struct struct_name
{
type element 1;
type element 2;
……………..
type element n;
}array name[size];

lets consider a 100 no of students and their whole data should be stored.so we use arrays to store 100 students data.if we use single structure that will become complicated.

example:

#include <stdio.h>
struct student {
int roll;
char name[20];
char course[20];
int marks ;
};
main( )
{
struct student stud[20];
int i,n;
printf ("Enter the no of students\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the details of %d st student \n",i+1);
printf("name of the student \n");
scanf("%s",stud[i].name);
printf("enter roll no\n");
scanf("%d",&stud[i].roll);
printf("enetr course\n");
scanf("%s",stud[i].course);
printf("enter the marks\n");
scanf("%d",&stud[i].marks);
}
printf("STUDENTS DETAILS:\n");
for(i=0;i<n;i++)
{
printf("\nRoll number:%d\n",stud[i].roll);
printf("Name:%s\n",stud[i].name);
printf("Totel mark:%d\n",stud[i].marks);
printf("course is %s",stud[i].course);
}
}