C Nested Structures

C Tutorial

1. What are C Nested Structures?

  • A C Nested Structures 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:

Name: Alice
DOB: 15-08-2005

3. Nested Structures with Pointers


 

Output:

Name: Alice
DOB: 15-08-2005

Use -> operator when accessing members through a pointer.


4. Example: Employee with Address


 

Output:

Employee: Bob, ID: 101
Address: Mumbai, Maharashtra - 400001

5. Key Points About Nested Structures

  1. Nested structures allow grouping related structures into one.

  2. Access nested members using dot . operator for normal variables.

  3. Access nested members using arrow -> operator for pointers.

  4. Useful for complex records like employee, student, or product information.

  5. Can be combined with arrays for multiple records.

You may also like...