as

Thursday, 13 November 2014

Array of Structure in C


C Structure is collection of different data types ( variables ) which are grouped together. Whereas, array of structures is nothing but collection of structures. This is also called as structure array in C.
#include<stdio.h>
void main()
{
   struct dept
   {
     int id;
     char name[15];
   }stru[3];

  int i=0;
  for(i=0;i<=2;i++)
   {
    printf("\n Enter id :" );
    scanf("%d",&stru[i].id);
     printf("\n Enter name:");
     scanf("%s",stru[i].name);
    }
   for(i=0;i<=2;i++)
   {
      printf("\n id=%d name=%s", stru [i].id, stru [i].name);
   }
getchar();
}







Sponsored Links

Popular Posts

Comments

ShareThis

Google+ Followers

Google+ Badge