C – Nested Structures

Nested structures: Defining a structure inside another structure.We access the elements of nested structure using outer structure reference variable.

struct Emp
            int num;
            float salary;
struct Employee
            struct Emp e;
            char name[20];
int main()
            struct Employee x;
            printf(“Enter emp details(num, name, salary) : “);
            scanf(“%d%s%f”, &x.e.num, x.name, &x.e.salary);
            printf(“Emp name is : %d \n”,x.e.num);
            printf(“Emp name is : %s \n”,x.name);
            printf(“Emp name is : %f \n”,x.e.salary);
            return 0;
Scroll to Top