Nested Structure in C
Nested structure in c language can have another structure as a member. There are two ways to define nested structure in c language:
- By separate structure
- By Embedded structure
1) Separate structure
We can create 2 structures, but dependent structure should be used inside the main structure as a member. Let's see the code of nested structure.
As you can see, doj (date of joining) is the variable of type Date. Here doj is used as a member in Employee structure. In this way, we can use Date structure in many structures.
2) Embedded structure
We can define structure within the structure also. It requires less code than previous way. But it can't be used in many structures.
Accessing Nested Structure
We can access the member of nested structure by Outer_Structure.Nested_Structure.member as given below:
C Nested Structure example
Let's see a simple example of nested structure in C language.
Output:
employee id : 101employee name : Sonoo Jaiswalemployee date of joining (dd/mm/yyyy) : 10/11/2014
No comments:
Post a Comment