当前位置:网站首页>Value transmission and address transmission of C language, pointer of pointer
Value transmission and address transmission of C language, pointer of pointer
2022-07-29 04:02:00 【Xiaowa 123】
When the function is called : Value and address
The secondary pointer :
int a=5;
int* p=&a;
int** p1=&p;
printf("a=%d, *p=%d, **p1=%d", a, *p, **p1); The result is 5,5,5
*p: p The value of is a The address of ,p Point to a,*p Just look at p The variable value on this address ,*p Yes. p The variable value on the stored address , Not to see p The value of this variable (p The variable value of is the address , see p The variable value of should be to see p Value , Not through *p The way ,*p Is to look at pointer variables p The value of the variable on the address pointed to !)
**p1 That is to say *(*p1),*p1 Just look at p1 The variable value on the stored address ,p1 The value of is p The address of , therefore *p1 Namely p Value , therefore **p1 Namely *p=a.
* Address = The value of the variable occupying this address ≠ The value of the address
**p1:*(*p1),p1 Put pointer variables p The address of , therefore *p1 It's a pointer variable p
* Whose address = Whose value
c The value and address of language - Baidu library c
Pass value : Do not change the value of the real parameter in the main function
Byref : Pass the address of the variable in the main function directly to other functions for use , Changed the actual value of the real parameter in the main function .
The difference is this : Passing values only works inside the function , If it's an address , After a functional process , The arguments in the main function can be actually changed .
For arrays , Because arrays usually occupy a large amount of memory , The system will not copy another piece of memory in the memory space of the function for value transfer like value transfer , Instead, send the address directly , Directly change the actual parameter value of the array .
The system is quite strict with the memory of the array .
It also involves the pointer of the pointer :

Byref : You want to actually change the value of which argument through the function , Just pass in the address of this argument .
The pointer of the pointer :
If the pointer is main An argument in the main function , And want to change the value of the pointer , What should be passed to the function parameter is main Address of argument pointer in function .
The variable of which argument you want to actually change , Just pass in the address of the argument , Byref .
malloc- The pointer of the pointer - Address transmission or value transmission : Be careful : If you want to change the value of an argument through a function call , The address passed in should be the address of the argument , Instead of copying a copy of memory in the called function , This memory will disappear with the end of the called function .
malloc The allocated memory needs to be free In order to release , Apply inside the function malloc, Even if the function ends , It will not release this memory .
边栏推荐
- Shopify卖家:EDM营销就要搭配SaleSmartly,轻松搞定转化率
- Summary on the thought of double pointer
- 【redis系列】字符串数据结构
- VScode连接ssh遇到的问题
- SQL窗口函数
- First ALV program 2
- 从2019 年开始,你一定停止使用了这个营销策略…
- The list is not updated in real time when JS V-for data changes
- UCOS任务切换过程
- The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout
猜你喜欢

Lvs+keepalived high availability deployment practical application
![[BGP] small scale experiment](/img/58/877e5e454e9bab9d1bccb8fdd3b04d.png)
[BGP] small scale experiment

【深度学习CPU(番外篇)——虚拟内存】

BGP的基础配置---建立对等体、路由宣告

Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理

Malloc C language

安装ros的laser_scan_matche库所遇到的问题(一)

从2019 年开始,你一定停止使用了这个营销策略…

STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案

消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!
随机推荐
大佬们flink的JDBC SQL Connector现在不支持所有的数据库吗,例如vertica?
LDP --- 标签分发协议
这个报错是什么鬼啊,不影响执行结果,但是在执行sql时一直报错。。。连接maxComputer是使用
Typescript from getting started to mastering (19) enumeration types
flink-sql 如何设置 sql执行超时时间
一文学透MySQL表的创建和约束
Batch production and upload sales NFT opensea eth polygon
MySQL Part 3
力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)
Is the array name a pointer
店铺排名问题,如何解决?
String template of ES6 new features and methods to simplify objects and functions
Data mining -- code implementation of association analysis example (Part 2)
Solve the problem of garbled code when opening the project code in idea
Interview essential! TCP classic 15 consecutive questions!
Use case of arrow function of new features in ES6
BGP的基础配置---建立对等体、路由宣告
Shopify卖家:EDM营销就要搭配SaleSmartly,轻松搞定转化率
After I get the winfrom specific control ID from the database, I need to find the corresponding control through this ID and assign a value to the text text of the control. What should I do
OA项目之会议通知(查询&是否参会&反馈详情)