当前位置:网站首页>Fundamentals of C language: structure (elementary level)
Fundamentals of C language: structure (elementary level)
2022-07-20 06:58:00 【Tiger Taro's inheritance】
Catalog
One 、 Declaration of a structure
1. Basic knowledge of structure
A structure is a collection of values , These values are called member variables . Each member of a structure can be a variable of a different type .
A structure is a collection . Each member of the structure can be of different types .
Array Is a collection of elements of the same type , All elements in the array are of the same type .
2. Statement of structure
struct tag//( Structural tag )
{
//( Member list )
//( Type name Member variable name )
member-list;
}variable-list;//( Structure variable list )
for example :
typedef struct Stu
{
char name[20];// name
int age;// Age
char sex[5];// Gender
char id[20];// Student number
}Stu;// You can't lose the semicolon
struct: Structure keywords , It indicates a structure , The declaration of the structure must have struct.
Structural tag : It is you who name your structure type
struct Structural tag : This represents a structure type
Member list : You can have multiple members , Each member has its own data type and member variable name .
Structure variable list : There can be multiple variables , Is a variable created with a structure type , Generally, the list of structural variables is omitted and not written , First declare the structure , Then create structure variables .
3. Type of structure member
The members of a structure can be scalars 、 Array 、 The pointer , Even other structures .
4. Creation and initialization of structure variables
Creation of structure variables :
Type does not occupy memory , Only after creating variables with types can memory be used .
Initialization of structure variables :
initialization : Assign values to variables while creating them
Two 、 Access to structure members
Structural variable . Structure member variables
Structure pointer -> Structure member variables
1. Structure variables accessing structure members
Structural variables pass through the dot operator (.) Access structure members
2. Structure pointer to access structure members
Structure pointer through operator (->) Access structure members .
3、 ... and 、 Structural parameters
When structures transmit parameters , To transfer the address of the structure .
If the structural variable is passed , A formal parameter is a temporary copy of an argument , It will waste a lot of memory space .
If the address of the structure is passed , The parameter received a pointer , The formal parameter part only needs to open up a memory space of the size of the pointer variable , It only needs 4 Bytes or 8 Bytes , Reduce the waste of space .
边栏推荐
- Redis deletion strategy and elimination strategy
- Jedis
- [leetcode daily question] - 109 Ordered linked list transformation binary search tree
- 硅谷课堂第八课-腾讯云点播管理模块(三)
- 软件测试工程师的6+1种技能
- Macro operation of vim editor
- NFT访问工具PREMINT遭黑 损失超37万美元
- 走进企业系列 |StreamNative x 众安保险
- OGC WebGIS 常用服务标准(WMS/WMTS/TMS/WFS)速查
- CD 从抓轨到搭建流媒体服务器 —— 以《月临寐乡》为例
猜你喜欢
PHP支付宝转账到支付宝账号
"Taige experiment" SLA linkage static routing experiment
C language foundation day4 function notes
Activity. Onstop() delay 10 seconds? Detect, locate and repair it~
MySQL详细知识点总结 可以收藏啦
如何选择云笔记工具?可以用云笔记做什么?
【论文阅读】CoaT:Co-Scale Conv-Attentional Image Transformers
专访铃盛(RingCentral)何必苍:以不断创新的MVP赋能未来混合办公
dfs 牛客 迷宫问题
sql编辑器里面的红叉代表什么意思(toad、waterdrop都遇到过…)
随机推荐
注解开发
pdf.js 使用介绍
PIPNet:面向自然场景的人脸关键点检测《Pixel-in-Pixel Net: Towards Efficient Facial Landmark Detection in the Wild》
自己用U++写的植物大战僵尸豌豆射手部分逻辑记录
硅谷课堂第八课-腾讯云点播管理模块(三)
Live broadcast today | Apache pulsar meetup: vivo, Tencent cloud, bigo, Yunxing technology practice sharing
React. The data cached by context and Redux cannot be shared across browser tabs. How to solve it?
C语言基础Day4-函数笔记
AcWing 379. 捉迷藏 题解 (最小路径不重复点覆盖)
Right click on win11 to change to win10 mode
Live broadcast today | Apache pulsar meetup: vivo, Tencent cloud, bigo, Yunxing technology practice sharing
[literature reading] npe: an FPGA based overlay processor for natural language
Heavy! China open source map was officially launched, and we sincerely invite all open source communities to join us to create ~
MySQL详细知识点总结 可以收藏啦
U++常用类型转化及Lambda的常用形式及代理
win10 cdm下安装wfuzz报错的原因
【文獻閱讀】NPE: An FPGA-based Overlay Processor for Natural Language
17_ Collect form data
F. Equate Multisets(贪心)
手机开通银河证券账户安全吗?