Knowee
Questions
Features
Study Tools

Nested structure program in c

Question

Nested structure program in c

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is an example of a nested structure program in C:

#include <stdio.h>

// Define the nested structure
struct Employee {
    char name[50];
    struct Date {
        int day;
        int month;
        int year;
    } dob; // Date of Birth
};

int main() {
    // Declare and initialize a variable of type Employee
    struct Employee emp = {"John Doe", {15, 10, 1990}};

    // Print the data
    printf("Employee Name: %s\n", emp.name);
    printf("Date of Birth: %d/%d/%d\n", emp.dob.day, emp.dob.month, emp.dob.year);

    return 0;
}

In this program, we have a structure Employee that has a member dob of type Date, which is another structure. This is an example of a nested structure. The Employee structure is initialized with the name "John Doe" and a date of birth of 15/10/1990. The program then prints out this information.

This problem has been solved

Similar Questions

Structure of a C Program:

How do you access a member of a structure using a structure pointer in C?*1 pointWith the dot operator (.)With the arrow operator (->)With the ampersand (&)With the asterisk (*

StructuresThe following C declarationsstruct node { int i; float j;};struct node *s[10] ;define s to beOptionsAn array, each element of which is a pointer to a structure of type node.A structure of 2 fields, each field being a pointer to an array of 10 elements.A structure of 3 fields: an integer, a float, and an array of 10 elements.An array, each element of which is a structure of type node.

How do you declare a structure in C?struct { int a; float b; } myStruct;struct myStruct { int a, float b};struct myStruct { int a; float b; };struct myStruct int a; float b; myStruct;struct { int a; float b; };

Can we declare function inside structure of C Programming?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.