91-9990449935 0120-4256464 |
Nested Structure in CNested structure in c language can have another structure as a member. There are two ways to define nested structure in c language:
1) Separate structureWe 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 structureWe 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 StructureWe can access the member of nested structure by Outer_Structure.Nested_Structure.member as given below: C Nested Structure exampleLet's see a simple example of nested structure in C language. Output: employee id : 101 employee name : Sonoo Jaiswal employee date of joining (dd/mm/yyyy) : 10/11/2014
Next TopicC Union
|