当前位置:网站首页>Pointer of C language (1)
Pointer of C language (1)
2022-07-22 09:19:00 【fksfdh】
One 、 The pointer
1、 The pointer
Equivalent to indirect access to data ;
The pointer variable size is 4 byte ;
2、 Value passing and reference passing
Reference passing is also value passing , But it's the address ;
The essence of function call is value passing ;
#include <stdio.h>
// Value passed
void demo01(int a) {
a = 100;
}
// reference : Delivery address
void demo02(int* b) {
*b = 100;
}
int main()
{
int i;
i = 10;
printf(" Original value :%d\n",i);
demo01(i);
printf(" Value passed :%d\n",i);
demo02(&i);
printf(" reference %d\n",i);
return 0;
}
result :
reason :
(1)、 Check the memory address :
(2)、
Variable i Memory address of :
Variable a Memory address of :
Before the change :
After modification :
You can see the value passing , The value passed in the subfunction , Different memory addresses , Is the memory address of the subfunction on the stack ; Therefore, when modifying the value passed by value transfer , The value of the main function will not be modified
The following figure , You'll find variables b Memory addresses and variables a In the same , This is because demo01 After the function is executed , Free memory , So continue to implement demo02 I used demo01 The memory address after the function is released .
Variable b Memory address of :
See the variables b The value stored in the memory address of is , Variable i Memory address of , When using b It's equivalent to visiting a Memory address of , And change the value to 100, Just modify the original data .*
The execution process of function in memory :
When executed main function , Will open up a memory space in the stack ; When executing to a sub function demo01 when , Will open up a new piece of memory on the stack , Used to execute sub functions , The actual parameters will be copied to the sub function and copied to a Variable ; When the sub function is completed , Will reclaim this memory , So it's done demo01 after , Free memory , When executed demo02 when , It will open up new memory space , The actual parameters will be copied to the sub function and copied to b Variables are used to execute demo02 function ,b It's a pointer variable , The address is stored in .
边栏推荐
猜你喜欢
CopyOnWriteArrayList 浅析
JVM introduction
go-zero微服务实战系列(三、API定义和表结构设计)
真人踩过的坑,告诉你避免自动化测试新手常犯的10个错误
Seven parameters of thread pool
SerializationException: Could not read JSON: Unrecognized token “xxx“
"Everything is interconnected, enabling thousands of industries", the 2022 open atom global open source summit openatom openharmony sub forum is about to open
分省市县地理空间矩阵:地级市空间、地理距离矩阵等多指标数据集
VSCODE配置Markdown,以及Markdown基础语法
【干货】知识共享的障碍及解决方法
随机推荐
String str = new String(“abc“) 到底创建了几个变量?
dtcloud 使用自定义字体
EasyCVR平台设备分组新增以及编辑操作异常的问题修复
详解flex布局
ettercap详细使用教程
EasyCVR平台安全扫描提示Go pprof调试信息泄露的解决办法
好轮子收藏:一个支持几乎所有流行格式的图像加载库stb_image.h
Thinking of data storage scheme based on sub database and sub table
Collection集合框架
Chrome插件开发教程
单细胞论文记录(part18)--Spectral clustering based on learning similarity matrix
position: -webkit-sticky; /* for Safari */ position: sticky;
Leetcode-12: integer to Roman numeral
Hebei special access to this C language program first day to find all primes in 1-100
河北专接本C语言程序第一天 求1-100内的所有素数
[dry goods] obstacles and solutions to knowledge sharing
LeetCode·1720:解码异或后的数组
conda 常用功能记录
EasyCVR平台如何实现无需鉴权即可接入特殊设备?
npm指令没有反应