Array Strcture
Array Strcture
struct struct-name
{ datatype var1;
datatype var2;
--------------------
datatype varN;
};
struct struct-name obj [ size ];
#include<stdio.h>
struct Employee
{
int Id;
char Name[25];
int Age;
long Salary
};
void main() {
int i;
struct Employee Emp[ 3 ];
for(i=0;i<3;i++)
{
printf("\nEnter details of %d Employee",i+1);
printf("\n\tEnter Employee Id : ");
scanf("%d",&Emp[i].Id);
printf("\n\tEnter Employee Name : ");
scanf("%s",&Emp[i].Name);
printf("\n\tEnter Employee Age : ");
scanf("%d",&Emp[i].Age);
printf("\n\tEnter Employee Salary : ");
scanf("%ld",&Emp[i].Salary);
}
printf("\nDetails of Employees");
for(i=0;i<3;i++)
printf("\n%d\t%s\t%d\t%ld",Emp[i].Id,Emp[i].Name,Emp[i].Age,Emp[i].Salary);
Array within Structure
struct struct-name
{
datatype var1; // normal variable
datatype array [size]; // array variable
---------
---------
datatype varN;
};
printf("\nDetails of Employees");
printf("\n\tEmployee Id : %d",E.Id);
printf("\n\tEmployee Name : %s",E.Name);
printf("\n\tEmployee Salary : %f",E.Salary);
printf("\n\tEnter Employee House No : ");
scanf("%s",&E.Add.HouseNo);
printf("\n\tEnter Employee City : ");
scanf("%s",&E.Add.City);
printf("\n\tEnter Employee House No : ");
scanf("%s",&E.Add.PinCode);