Nested Structures
structure can have another structure as a member. There are two ways to define nested structure in c language:
1. By separate structure
2. By Embedded structure
1) Separate structure We can create 2 structures, but dependent structure should be used inside the main structure as a member. Let's see the code of nested structure
struct Date
{
int dd;
int mm;
int yyyy;
};
struct Employee
{
int id;
char name[20];
struct Date doj;
}emp1;
2) Embedded structure
struct Employee {
int id;
char name[20];
struct Date
{
int dd;
int mm;
int yyyy;
}
doj;
}emp1;
Accessing Nested Structure
We can access the member of nested structure by Outer_Structure.Nested_Structure.member as given below:
e1.doj.dd
e1.doj.mm
e1.doj.yyyy