Nested Structure in C Language

Nested structure in c language can have another structure as a member. Nested structure in C is nothing but structure within a structure. One structure can be declared inside other structure as we declare structure members inside a structure.

There are two ways to define a nested structure in c language:

By Separate structure

By Embedded structure

Separate structure

We can create 2 structures, but dependent structure should be used inside the main structure as a member.

1

2

3

4

5

6

7

8

9

10

11

12

13

structdate

{

intdd;

intmm;

intyyyy;

}

structBook

{

intprice;

charname[50];

structDate dop;

}b1;

As you can see, dop (date of publishing) is the variable of type Date. Here dop is used as a member in Book information structure.

Embedded Structure

We can define structure within the structure also. It requires less code than the previous example. But it can not be used in many structures.

1

2

3

4

5

6

7

8

9

10

11

12

structBook

{

intprice;

charname[50];

structdate

{

intdd;

intmm;

intyyyy;

}dop;

}b1;

Accessing Nested Structure

We can access the member of a nested structure by Outer_Structure.Nested_Structure.member as given below: