1- Array Of Structure
- The way we have "array of int's","array of float","array of char" similarly we have "array of structure".
- Array of structure is nothing but finite number of homogeneous structure variable,belonging to a structure.
- Contiguous memory is allocated for array of structure.
- We use array of structure when there is a need of large number of structure variable of same type.
#include<stdio.h>
#include<conio.h>
main()
{ struct emp
{ char name[15];
int age;
float ht;
};
struct emp e[5];
int i=0;
for(i=0;i<5;i++)
{printf("Enter name,age&height"):
scanf("%s %d %f ",&e[i].name,&e[i].age,&e[i].ht);
for(i=0;i<5;i++)
printf("\n Name=%s,Age=%d,Height=%f",e[i].name,e[i].age,e[i].ht);
getch();
}
Output:
Enter name,age&height Sudarshan
21
5.2
Name= Sudarshan,Age=21,Height=5.2
2- Copying Structure Variable
The way we can assign the value of one integer variable into another integer type variable,value of one float variable into another float type variable,similarly we can assign the value of one structure variable into another structure variable of same type.
Comments
Post a Comment
Please do not enter any spam link in the comment box.