Attention:
1 structure within a struct once again defines a struct but does not create an instance of the struct body
In other words, the variables inside the struct that are defined again are treated as member variables of the parent structure.
1 structTianchao2 {3 intdata;4 Charname[ -];5 structBeijing//a struct is defined within the structure again but no instances of the struct are created6 //In other words, the variables inside the struct that are defined again are treated as member variables of the parent structure .7 {8 Charstr[ -];9 intnum;Ten }; One }; A - voidMainww () - { the structTianchao T1; - //t1. There can be four variables here, but it's not a compiler problem here. - - //is no problem + /*t1.data = +; - t1.num=66; + sprintf (t1.name, "Goa"); A sprintf (t1.str, "gob");*/ at } - - structTianchao - { - intdata; - Charname[ -]; in structBeijinga Structural Body - to { + Charstr[ -]; - intnum; the}B1;//the first method of internal definition * structBeijinga structural Body B2;//the second type of internal definition $ };Panax Notoginseng - voidMain () the{}
1 //struct China2 //{3 //int data;4 //Char name[100];5 //struct Guiyang6 // {7 //Char str[100];8 //int num;9 //}a1;//It 's unclear why the A1 compiler must be added to identifyTen //}; One //void Main () A //{ - //struct China C1; - //c1.a1.num = $; the //sprintf (C1.A1.STR, "ad"); - //printf ("%d,%s", c1.a1.num,c1.a1.str); - // - //GetChar (); + //} - //Mode two + struct China A { at intdata; - Charname[ -]; - //define a struct inside the struct, create a struct variable, and the variable will be directly treated as a member - //But there is no instance of creating the struct body - //A variable inside a struct that is defined again is treated as a member variable of the parent structure - structGuiyang in { - Charstr[ -]; to intnum; + }a1; - structGuiyang B1; the }; * voidMain () $ {Panax Notoginseng structChina C1; -C1.b1.num = $; thesprintf (C1.B1.STR,"AD"); +printf"%d,%s", c1.b1.num,c1.b1.str); A the GetChar (); +}
Structural body nesting of structure 3