Anonymous Structures

Microsoft Specific —>

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.

END Microsoft Specific

Example

// Example of an anonymous structure
struct phone
{
   int  areacode;
   long number;
};

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

Jim.number = 1234567;