当前位置:网站首页>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
边栏推荐
- Fiddler use
- Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
- Queue storage and circular queue
- Log4net is in Net core usage
- Problem C: realize Joseph Ring with linked list
- Charles uses three ways to modify requests and responses
- Query stored procedures in PostgreSQL
- 为什么BI对企业这么重要?
- 浅学一下I/O流和File类文件操作
- 全新的ORM框架——BeetlSQL介绍
猜你喜欢

Log4net is in Net core usage

软件测试相关知识~

C interface

Test questions and some space wars

一文了解全面静态代码分析

超好用的【通用Excel导入功能】

A set of combination boxing to create an idea eye protection scheme

2022a special equipment related management (elevator) work license question bank and simulation examination

12.<tag-链表和常考点综合>-lt.234-回文链表

Configuration table and page information automatically generate curd operation page
随机推荐
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
QT dynamic translation of Chinese and English languages
Docker拉取mysql并连接
Téléchargement en vrac de fichiers - téléchargement après compression
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
MySQL query specifies that a row is sorted to the first row
L3-011 直捣黄龙 (30 分)
Explication détaillée des fonctions send () et recv () du programme Socket
浅学一下I/O流和File类文件操作
Huawei mobile ADB devices connection device is empty
Unity knowledge points (ugui)
2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
Comprehensive calculation of employee information
Use of ADB command [1]
Top 9 task management system in 2022
12.<tag-链表和常考点综合>-lt.234-回文链表
Test questions and some space wars
Is it difficult to choose binary version control tools? After reading this article, you will find the answer
超好用的【通用Excel导入功能】
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案