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,
Linux File name validity detection ( Essence )2020 year 6 month 26 day C# Class library Loop execution help class ELementUI select Multi select drop-down box to get all properties of the selected item element ui Drop down box search function java Compile time and runtime exceptions in MySql sentence Recursively find all subordinate departments of an input department vue vue-element-admin Summary of the project shiro-oauth Enable third party authentication login about Bellman-Ford Personal understanding of algorithms about Navicat for mysql Of 2003 error