A structure can be nested within another structure by declaring structure variable inside other structure.
Variable of address structure is nested within employee structure.We access the members of nested structure using . (dot operator) twice.
struct address
{
char phone[15],city[15];
int pincode;
};
struct employee
{
int id;
struct address a;
};
int main()
{
struct employee e1 = {1,"1234567","ABC","39"};
printf("%d\t%s\t%s\t%d",e1.id,e1.a.phone,e1.a.city,e1.a.pincode);
return 0;
}
Variable of address structure is nested within employee structure.We access the members of nested structure using . (dot operator) twice.
structure variable.nested structure variable.nested structure member
e1.a.phone
Nice
ReplyDelete