Structure within Structure : Nested Structure
- Structure written inside another structure is called as nesting of two structures
- A structure can be the member of another structure
Way 1 : Declare two separate structures
Accessing Nested Elements :struct date { int date; int month; int year; }; struct Employee { char ename[20]; int ssn; float salary; struct date doj; }emp1;
- As we know , Structure members are accessed using dot operator.
- 'date' structure is nested within Employee Structure.
- Members of the 'date' can be accessed using 'employee'
- emp1 & doj are two structure names (Variables)
How ?
Accessing Month Field : emp1.doj.month Accessing day Field : emp1.doj.day Accessing year Field : emp1.doj.year
Way 2 : Declare Embedded structures
Accessing Nested Members :struct Employee { char ename[20]; int ssn; float salary; struct date { int date; int month; int year; }doj; }emp1;
Accessing Month Field : emp1.doj.month Accessing day Field : emp1.doj.day Accessing year Field : emp1.doj.year


0 comments
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email