Structural body nesting of structure 3

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.