Structure type Array

Structure type Array

Structure type array can be created just like array of basic data types is created.

Example:

struct emp e[20];

In this example, array with name e of structure emp has been declared with size 20.


Program of structure type array.
#include<string.h>
#include<stdio.h>
struct emp
{
int empid;
char ename[20];
};
int main()
{
struct emp e1[3];
for(i=0;i<3;i++)
{
printf(“\nEnter employee id=”);
scanf(“%d”,&e1[i].empid);
printf(“\nEnter employee name=”);
fflush(stdin);
gets(e1[i].ename);
}
for(i=0;i<3;i++)
{
printf(“\nEmployee id = %d”,e1[i].empid);
printf(“\nEmployee Name = %s”,e1[i].ename);
}
return(0);
}
Output
Enter employee id =101
Enter employee name=amit

Enter employee id =102
Enter employee name=sumit

Enter employee id =103
Enter employee name=Rahul


Employee id = 101
Employee Name = amit

Employee id = 102
Employee Name =sumit

Employee id = 103
Employee Name =Rahul





Spread the love
Lesson tags: array of structure type in c, array within a structure in c, program of array of structure, program of array within a structure, read structure array in c, structure array in c
Back to: C Programming Language
Spread the love