structural morphology

What is structure

*
Structure is a kind of self defined " data type "

*
A new structure consisting of several basic data types or other structures " data type "

*
C Language structure (Struct) In essence, it is a kind of custom data type , But this kind of data type is complex , By int,char,float
And other basic types . You can think of the structure as an aggregation type .

In actual development , We can change a set of , But the variables used to describe the same thing are put into the structure .

Why use structure

*
It represents some complex information, such as various kinds of students " achievement "," subject "," full name ", All kinds of games " Gold coin "," integral ",

" gemstone "

It's not convenient to use basic data type only , Low code flexibility

 

Definition of structure

struct Structure name {

Member type member name ;

Member type member name ;

};

example

struct student {

int name[16]; // full name

int age; // Age

int tel; // Telephone

};

reminder

*
Members are separated by semicolons ;

*
End of structure with semicolon ;

Structure contains structure

*
example

struct student {

int name[16];

int age;

int tel;

};

struct _class {

struct student xiaohua;

struct student heige;

struct student xiaohong;

};

Initialization of structure

struct student {

int name[16];

int age;

int tel;

};

*
Mode 1

struct student xiaohua = {"xiaohua",18,10086};

*
Mode 2

strcut student xiaohua ;

strcpy(xiaohua.name,"xiaohua");

xiaohua.age = 18;

xiaohua.tel = 10086;

Include structs in initialization structs

struct student {

int name [16];

int age;

int tel;;

};

struct _class {

struct student xiaohua;

struct student xiaohua;

struct student xiaohua;

};

 

struct _class n1= {

{"xiaohua",18,10086},

{"xiaohong",15,10086},

{"xiaohei",17,10086},

};

 

 

reminder

strcpy(); stay vs2019 Need to add _s, as :strcpy_s();

If you don't add it, you will get an error :

*

 

reason :

*
Because vs Consider function strcpy(); unsafe , Recommended use vs Own function ;

 

Use of structures

*
c++ mode :

*

 

*
Output results :

*

 

*
C mode :

*

 

*
Output results :

*

 

*
Structure contains structure :

*

 

*
The output is :

*

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Some East 14 Pay change 16 salary , Sincerity or routine ? Browser kernel ( understand )java Four functional interfaces ( a key , simple )HashMap Explain in detail html Writing about cherry trees , Writing about cherry trees os Simple use of module