Explain Structure within a structure with example
Structures within a structure means nesting of structures. Nesting of structures is permitted in C.
struct employee
{
char name[10];
char department[10];
struct allowance
{
int basic_pay;
int da;
int hra;
int city_allowance;
}a1;
}emp;
struct allowance
{
int basic_pay’
int da;
int hra;
int city_allowance;
};
An inner structure can have more then one variable
struct employee
{
char name[10];
char department[10];
struct allowance a1;
}emp;
emp.a1.bacis_pay;
emp.a1.da;
emp.a1.hra;
emp.a1.city_allowance;
struct employee
{
char name[10];
char department[10];
struct allowance
{
int basic_pay’
int da;
int hra;
int city_allowance;
}a1,a2,a3;
}emp;
It is also permissible to nest more then one type of structure :
struct employee
{
int eid;
char name[10];
char dept[0];
struct personnel p1;
struct allowance a1;
}emp;