Skip to main content

Problem Statement

Write a C program that uses a nested structure to store a student’s name along with their date of birth (day, month, year).

Solution

#include <stdio.h>

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

struct Student {
    char name[50];
    struct Date dob;
};

int main() {
    struct Student s = {"Alice", {15, 8, 2003}};
    printf("%s was born on %d/%d/%d\n",
        s.name, s.dob.day, s.dob.month, s.dob.year);
    return 0;
}

Output

Alice was born on 15/8/2003