当前位置:网站首页>The second part of the travel notes of C (Part II) structural thinking: Zen is stable; all four advocate structure
The second part of the travel notes of C (Part II) structural thinking: Zen is stable; all four advocate structure
2022-06-27 13:38:00 【Xuanche_】

Catalog
( one ) Declaration of a structure
( Ii. ) Structure variable definition and initialization
《C travel 》 special column 《 Xiao Xuan's C Tour 》
( one ) Declaration of a structure
1.1 The basics of structure
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 .
stay C Language in , Structure (struct) It's a data structure , yes C Aggregate data types in languages (aggregate data type) One kind of . A structure can be declared as Variable 、 The pointer or Array etc. , In order to achieve more complex data structure . The structure is also the of some elements aggregate , these Elements are called members of the structure (member), And these members can be of different types , Members usually visit by name .
In the actual project , Structures are abundant . R & D personnel often use structures to encapsulation Some properties to form new types . because C The internal program of the language is relatively simple , Researchers often use structures to create new products “ attribute ”, The purpose is to simplify the operation .
The structure is in function Is not simple , Its main function is encapsulation . The advantage of encapsulation is that it can be reused . So that users don't have to care what this is , Just use it by definition .
To make a long story short , The appearance of structure can help us better describe a complex object .
1.2 Statement of structure
for example , Describe a student :
1.3 Type of structure member
The members of a structure can be scalars 、 Array 、 The pointer , Even other structures .
Members of a structure can contain other structures , You can also include a pointer to your structure type The pointer , And usually this kind of The pointer Is used to implement some more advanced data structures, such as Linked list and Trees etc. .
( Ii. ) Structure variable definition and initialization
( 3 ) Access to structure members
Structure variable access member The members of structural variables are through Dot operator (.) Access to the . The dot operator accepts two operands . for example :
We can see s There are members name and age ; How do we visit s Members of ?
Structure pointers access members that point to variables Sometimes we don't get a structure variable , It is Pointer to a structure . How do I access members ?
as follows :
( boss ) Structural parameters
Go straight to the code , Let's judge the following print1 and print2 Which function is better ?
The answer is : The preferred print2 function . reason :
Simply speaking : One is Value transfer call (1), One is Address call (2)
In this way, it can avoid repeatedly generating large structural space , Increase of efficiency
Conclusion : When structures transmit parameters , To transfer the address of the structure .
边栏推荐
- CMOS级电路分析
- 命令行编辑器 sed 基础用法总结
- Prometheus 2.26.0 new features
- [weekly replay] the 81st biweekly match of leetcode
- IJCAI 2022 | 用一行代码大幅提升零样本学习方法效果,南京理工&牛津提出即插即用分类器模块
- [tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (III)
- mysql 锁机制与四种隔离级别
- Axi bus
- [XMAN2018排位赛]通行证
- Daily question brushing record (6)
猜你喜欢

Completely solve the problem of Chinese garbled code in Web Engineering at one time

Deeply convinced plan X - system foundation summary

Tiktok practice ~ public / private short video interchange

SFINAE

Istio微服务治理网格流量管理核心资源控制器详解

这是什么空调?

Deep understanding of bit operations

Record number of visits yesterday

Pytoch learning 2 (CNN)

Bluetooth health management device based on stm32
随机推荐
内网学习笔记(8)
Number of printouts (solved by recursive method)
基于JSP实现医院病历管理系统
类模板中可变参的逐步展开
[安洵杯 2019]Attack
每日刷题记录 (六)
美国芯片再遭重击,继Intel后又一家芯片企业将被中国芯片超越
Cool in summer
On the complexity of software development and the way to improve its efficiency
Kotlin函数使用示例教程
Quickly set up a website to visit foreign countries, set up SS and start BBR to quickly surf the Internet
After 2 years of outsourcing, I finally landed! Record my ByteDance 3 rounds of interviews, hope to help you!
Learning records of numpy Library
crane:字典项与关联数据处理的新思路
Completely solve the problem of Chinese garbled code in Web Engineering at one time
L June training (day 27) - figure
POSIX AIO -- glibc 版本异步 IO 简介
Intranet learning notes (8)
Cesium realizes satellite orbit detour
How to split microservices












