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 id =103
Employee id = 102 Employee id = 103 |
Popular Books of Computer Science