Nesting of c and c ++ struct and nesting of struct

Source: Internet
Author: User

Nesting of c and c ++ struct and nesting of struct
Nesting of c and c ++ struct

/*************************************** * ******************************* // * Nested struct * C + + **//********************************** * **********************************/struct A {private: int a1 [20]; public: void initialize (); struct B {private: A * B; int * p; public: void initialize (A * ); void next (); int read; void set (int I) ;}; friend A: B ;}; void A: initialize () {memset (a1, 0, sizeof (a1);} void A: B: initialize (A * a) {B = a; p = a-> a1;} void A: B :: set (int I) {* p = I;}/* void main () {A a; A: B b1, b2; int I;. initialize (); b1.initialize (& a); b2.initialize (& a); for (I = 0; I <20; I ++) {b1.set (I ); b2.set (I );}} /*************************************** * ******************************** // * C * nested struct ***//*********************************** * **********************************/typedef struct A {int year; int month; int day ;}; typedef struct B {string name; int age; union {A aa;} xy; struct A aa1 ;}; void main () {B * b1 = NULL; b1-> xy. aa. day = 1991; b1-> aa1.month = 7; getchar ();}



Teach you about the nested structure of C language,

C language cannot achieve your idea. The structure itself has no value, and only the structure members have a value.

Typedef struct {
Float H;
Float L;
Float actual;
} Physic;

Typedef struct {
Physic v;
Physic p;
} Thing;
Thing RTU;
RTU. v. H = 123.456;
RTU. v. L = 0;
RTU. v. actual = 100;

How to place struct in the C language into the function body after nesting

You can add the form of a parameter to the function body for operation. You only need to match the form parameter with the actual parameter type. For example, if a [I]. riqi. year is of the int type, your function can be written as void fun (int I ).
 

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.