当前位置:网站首页>Pointer and pointer of pointer
Pointer and pointer of pointer
2022-06-22 03:35:00 【A rainy spring night】
(Owed by: Happy rain in spring night http://blog.csdn.net/chunyexiyu)
1. introduction
Pointer and pointer of pointer , In essence , Both are storage addresses , In terms of language characteristics , One is a layer of pointers , One is a two-level pointer .
2. Pointer and pointer of pointer
void* p;
void** pp = &p;
The pointer And The pointer of the pointer ;
2. 1. Internal view
It's all pointers , Stored an address ;
The difference lies in a common variable address , A memory pointer variable address ;
But from a memory perspective , Is a variable address value ;
2. 2. From the compiler's point of view
The inspection of it is different ;
The two are different for compiler checking , The pointer can be redirected once , The pointer of the pointer can be redirected twice ;
A pointer can point to an address ;
The pointer of a pointer can point to the address of a pointer ;
Pointers and pointers to pointers cannot be used interchangeably , But cast is also possible .
for example :
void* p = nullptr;
void** pp = &p;
void* pc = (void*)(pp);
void** ppc = (void**) (p);
3. Why a pointer with a pointer ?
Personally, I think , Maybe it's mainly the need of identification and compiler checking ;
Or from the perspective of storage use , Both are storage addresses , adopt * Redirect the variable of the address location pointed to , The storage functions are consistent ;
Usage scenario of pointer :
- Scenarios that meet the needs of compiler recognition
- Scenarios that meet the needs of function value transfer
3.1 Meet the needs of compiler recognition
for example :
The following scene ,pp Want to store the address of a variable , To point to this variable , The variable itself is a pointer ;
void *p;
void** pp = &p;
for example :
The following scene ,pp Want to point to an array , This array is an array of pointers ;
void* parray[] = {nullptr, nullptr};
void** pp = parray;
3.2 Scenarios that meet the needs of function value transfer
for example :
We want the variable to be assigned in the function , Usually, you can pass the variable address in the past , But the variable itself is a pointer p;
A single-layer pointer passes a variable p Value ( That is to say p The direction of ), A double-layer pointer can pass through p The address of ;
void *p = nullptr;
getResource(&p);
void getResource(void** p){
*p = new xxx(...);
}
— Personal understanding , For reference only
(Owed by: Happy rain in spring night http://blog.csdn.net/chunyexiyu)
边栏推荐
- [nvme2.0b 10] controller shutdown and NVM subsystem shutdown
- Wechat applet onpagescroll is invalid
- Runtime package for golang concurrent programming
- AtCoder Beginner Contest 252(dijkstra,逆向思维)
- 装饰器《二》 property - 简答逻辑
- 3000 yuan projector comparison and evaluation, dangbei D3x beats Jimi new Z6 x
- Selenium entry level project - Doudou quiz
- 逆向crackme之ESp定律脱壳
- 倍福CX9020(WINCE 7)控制器使用方法和操作
- 3DE robot suction cup grabbing box
猜你喜欢

聊聊flink水位线

R数据分析:临床预测模型中校准曲线和DCA曲线的意义与做法

Kubernetes介绍和使用

How to break through the sales dilemma of clothing stores

svn与cvs的区别有哪些
![[nvme2.0b 9] controller initialization process](/img/70/536b2c850c611d5d0c013586d4c2d5.png)
[nvme2.0b 9] controller initialization process

R data analysis: significance and practice of calibration curve and DCA curve in clinical prediction model

3DE robot suction cup grabbing box

3DE recover from design

利用yolov5训练自己的数据集; yolov5的安装与使用 ; yolov5源码解读
随机推荐
所有项目的资源
Wechat applet onpagescroll is invalid
Rabbmitmq publish subscribe mode < 2 >
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
Decorator II property - short answer logic
利用yolov5训练自己的数据集; yolov5的安装与使用 ; yolov5源码解读
ASUS reinstallation system keyboard lamp failure = & gt; Refitting the ATK drive
工厂模式
When 618 attacks, how to choose between Beibei X3 and Jimi h3s? Take you all-round in-depth analysis
If you specify it as a gateway, does it become a gateway
std::make_shared特点
倍福TwinCAT3第三方伺服电机——以汇川IS620N伺服为例子
倍福TwinCAT设置PLC的扫描周期,运行周期方法
Explanation of atomic operation in golang concurrent programming
装饰器《二》 property - 简答逻辑
618来袭,当贝X3和极米H3S怎么选?带你全方位深度解析
VIM common commands
[nvme2.0b 8] nvme queue arbitration mechanism
OAK相机如何实现同步?
倍福 PLC 字符串类型string操作