A structure with in a structure means nesting of structure. Nesting structure is permitted in C. let us consider the following structure where a employee structure is defined with in department structure.
Example:
struct department
{
char name[20];
struct emp
{
int id;
int salary;
char address[30];
}e;
}d;
The innermost member in a nested structure can be accessed as
d.e.id;
d.e.sal;
d.e.address;
We can also create nested structures by using tag name that is one structure variable as a member of another structure.
Let us consider the following example where the structure variable of department structure us a member of employees structure
Example:
struct department
{
char name[20];
int id;
}
struct employee
{
int salary;
struct department d; // one structure variable as member of another structure member
}
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.