当前位置:网站首页>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 Stu
As a data type ,s Is to create a to store dataStructure object
,s
The data in it isMember name
staystruct Stu
When 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 name
In 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);
ps
Is 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->name
It meansps
Point tos
Members of thename
, and(*ps).name
It means the same thing
版权声明
本文为[Learn a little every day]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230321595309.html
边栏推荐
- How to achieve centralized management, flexible and efficient CI / CD online seminar highlights sharing
- 《C语言程序设计》(谭浩强第五版) 第8章 善于利用指针 习题解析与答案
- [mock data] fastmock dynamically returns the mock content according to the incoming parameters
- 2022g2 boiler stoker examination question bank and online simulation examination
- 研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
- socket編程 send()與 recv()函數詳解
- Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer
- L3-011 直捣黄龙 (30 分)
- MySql分组查询规则
- [untitled]
猜你喜欢
. net 5 Web custom middleware implementation returns the default picture
Idea view history [file history and project history]
Unity knowledge points (ugui 2)
Explanation keyword of MySQL
Optimization of especially slow startup in idea debugging mode
General test technology [II] test method
Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
IOTOS物联中台对接海康安防平台(iSecure Center)门禁系统
Eight elder brothers chronicle [4]
随机推荐
Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
POI create and export Excel based on data
General test technology [II] test method
Optimization of especially slow startup in idea debugging mode
二进制文件版本控制工具选择难?看完这篇你会找到答案
2022 团体程序设计天梯赛 模拟赛 L2-1 盲盒包装流水线 (25 分)
Supersocket is Used in net5 - command
Cefsharp stores cookies and reads cookies
[MySQL] left function | right function
MySql关键字GROUP_CONCAT,组合连接查询
Unity knowledge points (ugui)
2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
一文了解全面静态代码分析
MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
数据库表中不建索引,在插入数据时,通过sql语句防止重复添加(转载)
Five tips for cross-border e-commerce in 2022
超好用的【通用Excel导入功能】
C abstract class
Problem B: small challenge
Using swagger in. Net5