C Nested Structures
1. What are Nested Structures?
-
A nested structure is a structure that contains another structure as a member.
-
Useful for representing complex data objects like a student with an address, or an employee with a date of joining.
Syntax:
2. Example: Student with Nested Date of Birth
Output:
3. Nested Structures with Pointers
Output:
Use
->operator when accessing members through a pointer.
4. Example: Employee with Address
Output:
5. Key Points About Nested Structures
-
Nested structures allow grouping related structures into one.
-
Access nested members using dot
.operator for normal variables. -
Access nested members using arrow
->operator for pointers. -
Useful for complex records like employee, student, or product information.
-
Can be combined with arrays for multiple records.
