Separate structure

Nested structure in c language can have another structure as a member.
There are two ways to define nested structure in c language :
  • By separate structure
  • By Embedded structure

Separate Structures :
We can create 2 structures, but dependent structure should be used inside the main structure as a member.

struct Date
{
    int dd;
    int mm;
    int yyyy;
};
struct Employee
{
    int id;
    char name[20];
    struct Date doj;
}emp1;

As you can see, doj (date of joining) is the variable of type Date. Here doj is used as a member in Employee structure.

Post a Comment

0 Comments