Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Anonymous Structures

A Microsoft C extension allows you to declare a structure variable within another structure without giving it a name. These nested structures are called anonymous structures. C++ does not allow anonymous structures.

You can access the members of an anonymous structure as if they were members in the containing structure.

// anonymous_structures.c
#include <stdio.h>

struct phone
    int  areacode;
    long number;

struct person
    char   name[30];
    char   gender;
    int    age;
    int    weight;
    struct phone;    // Anonymous structure; no name needed
} Jim;

int main()
    Jim.number = 1234567;
    printf_s("%d\n", Jim.number);   
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.