当前位置:网站首页>Part 1 - Chapter 2 pointer operation
Part 1 - Chapter 2 pointer operation
2020-11-08 19:28:00 【Li Lihao】
stay C In language , For any type T, Can be in T A corresponding variable containing the address of the object is generated at the memory address where it is located . This variable , It's actually a variable that points to an object , therefore , These variables are called The pointer .
Pointers are precise and efficient tools for building data structures and manipulating memory .
Chapter structure
- Pointer basis
- Storage allocation
- Arithmetic operations on data sets and pointers
- As a pointer to a function parameter
- The pointer to the pointer
- Generic pointers and type conversions
- A function pointer
Pointer basis
A pointer stores the address of the data in memory, not the data itself .
The best way to understand pointers : Charting .
- The pointer is usually linked by position with arrows , Instead of drawing the actual address in the icon .
- When the pointer complements any data ,, That is, the pointer is set to NULL when , Use two vertical lines to show .
- Dangling pointer : Pointer to an invalid address .
Some examples of errors that may result in dangling pointers : Cast any integer variable into a pointer variable ; Manipulating pointers that exceed the bounds of the array ; Release one or more pointers that are still referenced .
Storage allocation
The size of pointer variables is usually related to the compiler settings and some specific C Implementation of the Type qualifiers of .
- You must remember : When you declare a pointer , It just allocates space for the pointer itself , There is no space allocated for the data referenced by the pointer .
by Data allocation space Two methods of :
- (1) Declare a variable directly
- (2) Dynamically allocate storage space at runtime ( for example : Use malloc or realloc).
When you declare a variable , What happened?
When you declare a variable , The compiler will reserve enough memory space according to the type of variable .
The storage space of variables is automatically allocated by the system , But this storage space does not exist permanently throughout the life cycle of the program .
The automatic variable is A variable whose storage space can be automatically allocated and released when entering or leaving a module or function
stay C In language , When you want to dynamically allocate storage space , You get a pointer to a heap storage space ( The first 3 Chapter ), This storage space is managed by us , And it will always be there , Unless we explicitly release it .
As a pointer to a function parameter
stay C The function in the call language plays an important role . most important of all , Pointers support passing parameters as references to functions ( Call by reference ).
When passing parameters by reference , When the function changes this parameter , The value of the changed parameter will always exist , Even after the function exits . When a pass function is called by value , At this point, the value change can only last until the function returns .
It is an efficient way to pass large and complex function parameters with pointers : Because it's just passing a pointer instead of a full copy of the data into the function , This can greatly save memory space
Call the pass function by reference
版权声明
本文为[Li Lihao]所创,转载请带上原文链接,感谢
边栏推荐
- VirtualBox安装centos7
- I used Python to find out all the people who deleted my wechat and deleted them automatically
- 总结: 10月海外DeFi新项目,更多资管策略来了!
- Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
- Not a programmer, code can't be too ugly! The official writing standard of Python: pep8 everyone should know
- 中缀表达式转后缀表达式
- Liteos message queuing actual combat
- PHP generates unique strings
- experiment
- Jsliang job series - 07 - promise
猜你喜欢

C / C + + knowledge sharing: function pointer and pointer function, can you understand after reading this article?

One minute comprehensive understanding of forsage smart contract global shared Ethereum matrix plan

使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性

快来看看!AQS 和 CountDownLatch 有怎么样的关系?
![[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!](/img/4b/176185ba622b275404e2083df4f28a.jpg)
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!

go语言参数传递到底是传值还是传引用?

Mongodb database

接口测试用例思路总结

给大家介绍下,这是我的流程图软件 —— draw.io

动态规划设计:最大子数组
随机推荐
使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性
简明 VIM 练级攻略
Awk implements SQL like join operation
解决go get下载包失败问题
搭载固态硬盘的服务器究竟比机械硬盘快多少
c++ opencv4.3 sift匹配
Use markdown
Dynamic query processing method of stored procedure
SQL quick query
TypeScript(1-2-2)
数组初相识
How much disk IO does a byte of read file actually take place?
Exercise 5
experiment
Implementation of warehouse management system with ABP (net core) + easyUI + efcore
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
Part I - Chapter 1 Overview
Regular backup of WordPress website program and database to qiniu cloud
MongoDB增删改查操作
Flink series (0) -- Preparation (basic stream processing)