Nearby lessons

61 of 72

C - Nested Structures

A nested structure means one structure is used as a member inside another structure. For example, a student record can contain an address.

1. Example of a Nested Structure

Here, Address stores a city and a PIN code. The Student structure contains an Address member named address.

Example01
Loading editor…

2. Understand the Dot Operator

  • s1.name accesses the student's name.
  • s1.address accesses the address structure.
  • s1.address.city accesses the city inside the address.
  • s1.address.pinCode accesses the PIN code inside the address.

Common Mistakes

  • Use the exact member names defined in both structures.
  • Use a dot for each level of a nested structure.
  • Make sure the inner structure type is defined before using it as a member.
📝 Key Takeaways
  • A structure can contain another structure as a member.
  • Use more than one dot to access a nested member.
  • For example, student.address.city accesses the city inside the student address.

🧠 Test Your Knowledge

1 Questions
Progress: 0 / 1

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.