当前位置:网站首页>Explain C language 12 in detail (C language series)
Explain C language 12 in detail (C language series)
2022-07-28 21:23:00 【Cream dimple* ٩ ( ˊωˋ*)و*】
Catalog
The grammatical structure of the structure :
The relationship between structure and object :
Select the reason for the address call :
Preface :
Let's discuss with you this time C The structure of language , This section is just a brief introduction to the structure , For more detailed explanation, please refer to the sharing with you in the later small and medium-sized editors .
The concept of structure :
In Xiaobian's view, a structure is a set of values , But the types of values can be different .
The grammatical structure of the structure :

How to call a structure :
When an object is created in the main function, the structure is called , As shown in the figure below .

The relationship between structure and object :
The structure type is just like the drawing in our life , When we create a structure object in the main function , We can regard it as our house , When we want to build a house, the internal structure of the house needs drawings to show us . Similarly, when we create a structural variable , We need to know the specific types of this object .( As shown in the figure below )

Access to structure members :
. Access and -> visit
See the following code for details :
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
struct B
{
char c;
short s;
double d;
};
struct stu
{
struct B sb;
char name[20];
int age;
char id[20];
};
int main()
{
struct stu s = { {'w',20,3.14}," Zhang San ",30,"202220034" };
// use “.” visit
printf("%c\n", s.sb.c);
// use “->” visit
printf("%s\n", s.id);
// When using pointer access
struct stu* ps = &s;
// use “.” visit
printf("%c\n", (*ps).sb.c);
// use “->” visit
printf("%s\n", ps->id);
return 0;
}The code runs as follows :
Structural parameters :
Value transfer call :
The code is as follows :
#define _CRT_SECURE_NO_WARNINGS 1
// Value transfer call
#include<stdio.h>
struct B
{
char c;
short s;
double d;
};
struct stu
{
struct B sb;
char name[20];
int age;
char id[20];
};
void print1(struct stu t)
{
printf("%c %d %lf %s %d %s\n", t.sb.c, t.sb.s, t.sb.d, t.name, t.age, t.id);
}
int main()
{
struct stu s = { {'w',20,3.14}," Zhang San ",30,"202220034" };
print1(s);// Value transfer call
return 0;
}The code screenshot is as follows :

shortcoming : Most of the space is wasted when calling by value .
Address call :
The code is as follows :
#define _CRT_SECURE_NO_WARNINGS 1
// Address call
#include<stdio.h>
struct B
{
char c;
short s;
double d;
};
struct stu
{
struct B sb;
char name[20];
int age;
char id[20];
};
void print2(struct stu* ps)
{
printf("%c %d %lf %s %d %s\n", ps->sb.c, ps->sb.s, ps->sb.d, ps->name, ps->age, ps->id);
}
int main()
{
struct stu s = { {'w',20,3.14}," Zhang San ",30,"202220034" };
print2(&s);// Address call
return 0;
}The code screenshot is as follows :

advantage : Higher efficiency of parameter transmission , And you can change the original value .
Select the reason for the address call :
When a function passes parameters , Parameters need to be stacked . If you pass a structure object , The structure is too large , The system overhead of parameter stack pressing will be relatively large , So it will lead to performance degradation .
Conclusion :
When structures transmit parameters , Pass the address of the structure .
Conclusion :
This editor mainly shares a small part of knowledge about structure with you , Pay attention to small make up , Xiaobian will take you to continue to explore the deeper knowledge behind , Remember to like it, or you won't find it next time ! I hope that's helpful , If there are any mistakes in the article, you are also welcome to point out the maze for Xiaobian in time ( I'd like to thank you guys first !)
边栏推荐
- Uncaught Error:Invalid geoJson format Cannot read property ‘length‘ of undefind
- 九鑫智能正式加入openGauss社区
- 又一款装机神器
- Unity3d tutorial notes - unity initial 02
- Cloud security core technology
- Redis缓存雪崩、缓存穿透、缓存击穿
- Unity3d tutorial notes - unity initial 04
- (PMIC) full and half bridge drive csd95481rwj PDF specification
- System integration under microservice architecture
- SSM use @async and create threadpooltaskexecutor thread pool
猜你喜欢

职场高薪 |「中高级测试」面试题

High salary in the workplace | "intermediate and advanced test" interview questions

云安全核心技术

速卖通测评自养号,国外环境如何搭建?需要多少成本?

Api 接口优化的几个技巧

After Europe, it entered Japan and South Korea again, and the globalization of Pico consumer VR accelerated

Moco V2: further upgrade of Moco series

C language function program example (super complete)

探讨:想要落地DevOps的话,只考虑好的PaaS容器平台就够了么?

Cloud security core technology
随机推荐
牛客打开摄像头几秒后画面消失 | 相机打开画面一闪一闪
Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
工业通讯领域的总线、协议、规范、接口、数据采集与控制系统
Attribute based encryption simulation and code implementation (cp-abe) paper: ciphertext policy attribute based encryption
Several skills of API interface optimization
多线程顺序运行的 4 种方法,面试随便问
Buuctf questions upload labs record pass-11~pass-20
实习日记第一周
九鑫智能正式加入openGauss社区
Bus, protocol, specification, interface, data acquisition and control system in industrial communication field
Api 接口优化的几个技巧
Backup and recovery of SQL Server database
ICML2022 | 时序自监督视频transformer
Introduction to blue team: efficiency tools
CVPR 2022 | in depth study of batch normalized estimation offset in network
Redis缓存雪崩、缓存穿透、缓存击穿
小程序容器技术,让移动研发效率提升500%
Deit: attention can also be distilled
Top level "redis notes", cache avalanche + breakdown + penetration + cluster + distributed lock, Nb
Learning typescript (II)