当前位置:网站首页>Punch in: 4.23 C language chapter - (1) first knowledge of C language - (12) structure
Punch in: 4.23 C language chapter - (1) first knowledge of C language - (12) structure
2022-04-23 03:23:00 【Learn a little every day】
C Language -(1) First time to know C Language - (12) Structure
Structure
The structure is C Especially important knowledge points in language , The structure makes C Language has the ability to describe complex types .
For example, describe students , Students include : name + Age + Gender + Student number These information .
Describe a Book , This book includes : Title + Press. + Catalog + Author, etc
These are complex objects ,C Language gives you the ability to customize types
One of the custom types is called : Structurestruct
Structure is the practice of combining some single types
for example , Let's now describe a person , He has a name + Age + Gender + Student number These information
struct Stu
{
char name[20];// name
int age; // Age
char sex[5]; // Gender
char id[15]; // Student number
};
int main()
{
return 0;
}
We're going to build a house ,struct Stu It's our drawing , Create a structure object s, Fill in the data according to the drawing
Initialization of structure
// Print structure information
struct Stu s = {
" Zhang San ", 20, " male ", "20180101"};
You can put
struct StuAs a data type ,s Is to create a to store dataStructure object,sThe data in it isMember namestaystruct StuWhen not in use , Those types inside won't open up space
//. Access operators for structure members
printf("name = %s age = %d sex = %s id = %s\n", s.name, s.age, s.sex, s.id);
To print s The message inside , To print in the order of types ,
" Zhang San ", 20, " male ", "20180101"Corresponding%s,%d,%s,%s, The order cannot be reversed , And in accordance withStructure object . Member nameIn the form of
There's another way to print
//
struct Stu *ps = &s;
printf("name = %s age = %d sex = %s id = %s\n", (*ps).name, (*ps).age, (*ps).sex, (*ps).id);
psIs a struct pointer variable , Here is the method of pointer there , But it's a bit of a hassle , It can be used directly->The operator
struct Stu *ps = &s;
printf("name = %s age = %d sex = %s id = %s\n", ps->name, ps->age, ps->sex, ps-
>id);
ps->nameIt meanspsPoint tosMembers of thename, and(*ps).nameIt means the same thing
版权声明
本文为[Learn a little every day]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230321595309.html
边栏推荐
- 集合之List接口
- A set of combination boxing to create an idea eye protection scheme
- QT learning summary
- QT uses drag and drop picture to control and mouse to move picture
- Mysql database
- Test experience data
- Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD
- JS, bind the event for a label with input, and then bind the stand-alone event in the parent element. The event is executed twice and solved
- QT dynamic translation of Chinese and English languages
- 《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
猜你喜欢

Flink customizes the application of sink side sinkfunction

Experiment 5 components and event handling

2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination

. net webapi access authorization mechanism and process design (header token + redis)

QT learning summary

2022 团体程序设计天梯赛 模拟赛 L2-4 哲哲打游戏 (25 分)

TCP three handshakes and four waves

File upload vulnerability summary and upload labs shooting range documentary

Supersocket is Used in net5 - command

Visual programming -- how to customize the mouse cursor
随机推荐
Test experience data
Cefsharp stores cookies and reads cookies
Docker pulls MySQL and connects
Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
Super easy to use [general excel import function]
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
Scenario Title: how does system a use the page of system B
There is no index in the database table. When inserting data, SQL statements are used to prevent repeated addition (Reprint)
Super easy to use asynchronous export function of Excel
Configuration table and page information automatically generate curd operation page
How to achieve centralized management, flexible and efficient CI / CD online seminar highlights sharing
C-11 problem I: find balloon
通过 zxing 生成二维码
Generate QR code through zxing
Student achievement management
Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
IOTOS物联中台对接海康安防平台(iSecure Center)门禁系统
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
你真的懂hashCode和equals吗???
12.<tag-链表和常考点综合>-lt.234-回文链表