A nested structure is a structure that contains another structure as one of its members. It is useful when a record contains another related record.
A nested structure is a structure that contains another structure as one of its members. It is useful when a record contains another related record.
A student record may contain personal information and an address. The address itself can be represented using another structure.
Nested structures help organize complex information by dividing it into smaller related structures. This makes a large record easier to understand and manage.
A Student structure can contain an
Address structure for storing city and PIN code.
Here, address is a member of Student,
and its type is struct Address.
A member inside the nested structure is accessed by using the dot operator twice: first for the outer structure member and then for the inner structure member.
Here, student is the outer structure variable,
address is its nested structure member, and
pinCode and city are members of
the nested structure.
A company employee record may contain employee details and a separate address record. The address can be stored as a nested structure inside the employee structure.
Employee → Name, ID, Address → City, PIN Code.
Write a C program using nested structures to store a student's roll number, city and PIN code, and display all the information.
First create an Address structure. Then use
struct Address as a member inside the
Student structure.
In a nested structure, one structure is included as a member of another structure. The inner structure members are accessed through the outer structure variable using the dot operator.
Enter roll number: 101
Enter city: Jaipur
Enter PIN code: 302001
Roll Number = 101
City = Jaipur
PIN Code = 302001
The expression s1.address.pinCode first accesses the
address member of s1 and then accesses
the pinCode member inside that nested structure.
Nested structures are useful when a single record contains smaller records that have their own related data.
Student → Address → City, PIN Code
| Concept | Remember |
|---|---|
| Nested Structure | A structure used as a member of another structure. |
| Outer Structure | The structure containing another structure. |
| Inner Structure | The structure used as a member inside the outer structure. |
| Member Access | Use the dot operator through the outer structure member. |
| Example | student.address.city |
Watch a beginner-friendly explanation of nested structures in C programming.
A short handwritten-style revision sheet for nested structures will be provided here.
Use the mind map for quick revision of outer structure, inner structure and member access.