Nested structure in C is nothing but structure within structure. We can declare one structure inside another structure using the concept of nested structure.

Syntax of nested structure
struct struct_name{
    member definition;
    member definition;
    ...
    ...
    struct nested_struct_name{
        member definition;
        member definition;
        ...
        ..
    } [one or more structure objects];
}[one or more structure objects];

OR

struct struct_name_1{
    member definition;
    member definition;
    ...
    ...
}[one or more structure objects];

struct struct_name_2{
    member definition;
    member definition;
    ...
    ..
    struct struct_name_1 object;
} [one or more structure objects];
Example
struct class{
    int roomNo;
    int seats;

    struct student{
    int rollNo;
    char name[20];
    }s;
}c;

Accessing nested structure elements

To access nested structure elements we use member access operator(.) For this we need to create the object of the structures.

Program to access members of nested structures in C

//An example of nested structure

#include<stdio.h>
#include<string.h>

struct student{
    int rollNo;
    char name[20];
};

struct class{
    int roomNo;
    int seats;
    
    struct student s;
};


int main()
{
    struct class c;
    
    c.roomNo = 102;
    c.seats = 40;

    c.s.rollNo = 12345;
    strcpy(c.s.name, "Richard");

    printf("Room No of class = %d\n", c.roomNo);
    printf("Seats available in class = %d\n", c.seats);
    printf("Roll no of student = %d\n", c.s.rollNo);
    printf("Name of student = %s\n", c.s.name);
    return 0;
}

Output


Room No of class = 102
Seats available in class = 40
Roll no of student = 12345
Name of student = Richard