Anonymous Structures in C

#include <stdio.h>

struct MyStruct
{
    int a;
    struct
    {
        int x;
        int y;
    }
} int main(void)
{
    struct MyStruct ms;
    ms.a = 100;
    ms.x = 200;
    ms.y = 300;
    printf("Outer field : %d\n", ms.a);
    printf("Inner field x: %d\n", ms.x);
    printf("Inner field y: %d\n", ms.y);

    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *