Array of Structure Variable

Like variables of built in data types it is also possible to create an array of structure variable.
Now suppose a class having 60 students and it is required to manage information of 60 students. In such situations array of structure is useful. Thus instead of declaring 60 individual structure variables only one array of 60 students can be declared.

struct structure_name array_name[SIZE]; 
struct Student S[60];

In above example S[0] represents First student, S[1] represents second student and so on.

struct student
   int rollno;
   char name [20];
void main ()
   clrscr ();
   struct student s[60];
   int i;
   for (i=0; i<60; i++)
      printf ("Enter Roll Number:");
      scanf ("%d", &s[i].rollno);
      printf ("Enter Name:");
      scanf ("%s", s[i].name);
   for (i=0; i<60; i++)
      printf ("Roll Number: %d\n", s[i].rollno);
      printf ("Name: %s\n", s[i].name);
   getch ();

Download Projects

Download Programs