当前位置:网站首页>error:指针作为函数参数错误总结
error:指针作为函数参数错误总结
2022-06-11 16:52:00 【NI3E】
我们知道,函数传递参数是“拷贝”,不是把原值传进去,除非参数是数组这样的“地址”。
当把指针作为函数参数传递进去,想当然的以为在函数里面修改了指针,在函数外面也保留指针的改变。
实际上,调用函数结束之后,指针的指向不会改变。
所以可以把新的指针指向作为返回值,通过赋值改变原来的指针指向。达到修改指针的目的。
2021-6-12补充
在用C写stack和list时候都遇到的问题。
已经知道“当指针作为函数参数传递进去时候,在函数里面修改了指针,函数外面指针指向不会改变,需要利用返回值来改变原指针指向”。但是上一次没有写清楚自己真正遇到的问题。
当我想要改变链式结构时候,采用了move函数计算算法允许的下一步位置,然后拟用int类型存放了步数,但是实际上我们需要保证函数运行的时候指针始终指向需要的位置(Head or tail),所以,嵌套函数时候,我们始终需要保证返回值都是指针,才能在main里面指针的位置正常。所以move里面调用了改变指向的函数,move返回值也就需要是指针。
也就是说,涉及这种链表的指针问题的时候,嵌套函数都应该满足返回值是指针。并且每一次调用都是“指针=函数(指针)”的形式,每一层都应该这样。
边栏推荐
- Solr (I) installation and permission control of Solr
- 做跨境电商卖什么产品好?热销类目有哪些?
- WYSIWYG markdown editor: typora
- 2022安全员-A证考试题模拟考试题库模拟考试平台操作
- RDKit教程
- Solve the problem that jupyter cannot connect to the kernel based on pycharm and Anaconda -- solution 1
- (validation file) validatejarfile report errors
- [ISITDTU 2019]EasyPHP
- 如何把树结构存储到数据库
- Drug evaluation index
猜你喜欢
![[Clickhouse column] create a new library, user and role](/img/e5/d11493a37e25b7dde6cc43b3828749.png)
[Clickhouse column] create a new library, user and role

微服务连接云端Sentinel 控制台失败及连接成功后出现链路空白问题(已解决)

Solve the problem that jupyter cannot connect to the kernel based on pycharm and Anaconda -- solution 1
Persistence mechanism of redis

学生网站模板棕色蛋糕甜品网站设计——棕色蛋糕甜品店(4页) 美食甜品网页制作期末大作业成品_生鲜水果网页设计期末作业

Composition of JVM

Analysis report on the "fourteenth five year plan" proposal and innovation environment of global and Chinese sodium pyrophosphate industry (2022-2028)

所见即所得的 markdown 编辑器:Typora

Elasitcsearch基础学习笔记(1)

Pycharm使用小技巧 - 如何设置背景图片
随机推荐
Database backup (MySQL)
Solve the problem that jupyter cannot connect to the kernel based on pycharm and Anaconda -- solution 1
Report on the operation situation and future prospects of China's gear oil industry (2022-2028)
C语言各数据类型的内存映像
ShellBrowser . NET Crack
啟牛商學院給的證券賬戶是安全的嗎?開戶收費嗎
VLAN partition and routing between VLANs
【opencvsharp】斑点检测 条码解码 图像操作 图像旋转/翻转/缩放 透视变换 图像显示控件 demo笔记
时序预测 | MATLAB实现RBF径向基神经网络时间序列未来多步预测
Tornado environment construction and basic framework construction -- familiar Hello World
A set of ThinkPHP wechat applet mall source code with background management
Is the stock account recommended by qiniu safe? Is it reliable
^32 execution context stack interview questions
Using MATLAB and dcraw to process digital camera raw files
^31 prototype interview questions
485天,我远程办公的 21 条心得分享|社区征文
The micro service failed to connect to the cloud sentinel console and the link blank problem occurred after the connection was successful (resolved)
Oracle 分析函数 over 和MySQL 实现类似效果写法
RDKit教程
Oracle数据库合并行记录,WMSYS.WM_CONCAT 函数的用和MySQL 中GROUP_CONCAT(id)的使用及比较。