---
title: "Nested structures with example"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:nested-structure-explain"
source: https://www.bctengineer.com/q/semester_1/computer_programming/nested-structure-explain
site: BCT Engineering
---

# Nested structures with example

Computer Programming · Chapter 8: Structures

- Asked in: 2070 Asar, 2 marks; 2073 Chaitra, 2 marks; 2073 Shrawan, 4 marks; 2067 Asoj, 2 marks; 2072 Kartik, 3 marks; 2070 Chaitra, 1 marks; 2074 Asoj, 3 marks (asked 7 times)
- Video: [65 - NESTED STRUCTURES - C PROGRAMMING](https://www.youtube.com/watch?v=46-J15Jb37I) — Sundeep Saradhi Kanthety
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/nested-structure-explain
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

What do you mean by nested structures? Explain nested structure with suitable example. (Need of nested structure; how can we create and use a structure within another.)

## Short answer

Nested structures contain another structure as a member, useful for hierarchical data like a date inside a student record. Define the inner structure first, then declare it in the outer; access members with dot operators, e.g., s.dob.month.

## Answer

#### Meaning
A **nested structure** is a structure that has another structure as one of its members. The inner structure must be defined before it is used in the outer structure.

#### Need
- Real-world data is often hierarchical: a student has a date of birth, which itself has day, month and year; an employee has an address.
- It groups related data, reuses one structure (such as `date`) in many places, and keeps the program readable.

#### Creating a nested structure
```c
struct date { int day, month, year; };

struct student {
    char name[30];
    int roll;
    struct date dob;       /* structure inside structure */
};
```
(The inner structure can also be defined inside the outer one.)

#### Using it
Members are reached by repeating the dot operator from the outside in: `s.dob.month`. It can be initialised with nested braces: `{"Sita", 12, {5, 8, 2005}}`.

```c
#include <stdio.h>

struct date {
    int day, month, year;
};

struct student {
    char name[30];
    int roll;
    struct date dob;          /* nested structure */
};

int main(void)
{
    struct student s = {"Sita", 12, {5, 8, 2005}};

    printf("Name: %s, Roll: %d\n", s.name, s.roll);
    printf("DOB : %d/%d/%d\n", s.dob.day, s.dob.month, s.dob.year);
    return 0;
}
```

Output:

```text
Name: Sita, Roll: 12
DOB : 5/8/2005
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is a nested structure?
   A. A structure defined inside a function only
   B. A structure that has another structure as one of its members
   C. An array of structures
   D. Two structures with the same tag
   Answer: B. Nesting means a member is itself a structure. (Key point: Definition)

2. What is required about the inner structure?
   A. It must be defined after the outer one
   B. It must be defined before it is used in the outer structure
   C. It must have no tag
   D. It must be a pointer
   Answer: B. The compiler must know the inner type before the outer uses it. (Key point: Definition order)

3. How is the month of the dob in student variable s accessed?
   A. s.month
   B. s->dob->month
   C. s.dob.month
   D. dob.s.month
   Answer: C. Dot operators are repeated from the outside in. (Key point: Access syntax)

4. Why use nested structures?
   A. Real-world data is hierarchical, and one structure like date can be reused in many places
   B. Because C does not allow other types in a structure
   C. To make the program run faster
   D. To avoid using member names
   Answer: A. Nesting models hierarchical data and promotes reuse. (Key point: Need)

## Related in Computer Programming

- [Define structure; need of structures](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-structure-need) — Computer Programming, chapter 8, asked 2×
- [Arrays within structures](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarrays-within-structures) — Computer Programming, chapter 8
- [College records with nested date structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-college-estdate) — Computer Programming, chapter 8
- [Height difference using nested structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-height-feet-inches) — Computer Programming, chapter 8
- [Nested function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Anested-function) — Computer Programming, chapter 6
- [Sort employee structures by salary](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-employee-sort-salary) — Computer Programming, chapter 8, asked 2×

## Related in other subjects

- [Why do we need DFT](https://www.bctengineer.com/question.md?key=semester_7%2Fdigital_signal_analysis_and_processing%3Awhy-need-dft) — Digital Signal Analysis and Processing, chapter 7, asked 6×
- [Why do we need FFT](https://www.bctengineer.com/question.md?key=semester_7%2Fdigital_signal_analysis_and_processing%3Awhy-need-fft) — Digital Signal Analysis and Processing, chapter 7, asked 2×
- [Project financing; structures; capital structure steps](https://www.bctengineer.com/question.md?key=semester_7%2Fproject_engineering%3Aproject-finance-define-structures-steps) — Project Engineering, chapter 6
- [Drop structures: need and types with sketches](https://www.bctengineer.com/question.md?key=semester_6%2Firrigation_and_drainage_engineering%3Adrop-structures-types-sketch) — Irrigation and Drainage Engineering, chapter 7, asked 6×
