Answer's Question about pointer
2024-09-03 16:59:08
When you create a new pointer, this will be in heap until you delete it.
So what you said is sort of mistake, "函数内部有个局部变量指针", then the pointer should not exist after the function return.
Therefore, you should delete the pointer before the program is done, or memory leak
int* add(){
int a =1;
int *Ptr=&a;
return Ptr; //for this Ptr is not actual local variable, because it be return, so other can use it
}
int add(){
int a =1;
int *Ptr=&a;
delete Ptr;
return 0; //for this Ptr is local variable, because it was deleted
}
最新文章
- SpringMVC 数据校验
- 前端相关的seo技术
- java日期int和String互转
- IOS 项目问题总结
- Jedis中的一致性hash
- Just do it!!!
- UILabel 的属性设置
- FileProvider解决FileUriExposedException
- “IAsyncOperation<;StorageFile>;”不包含“GetAwaiter”的定义
- NGUI_Font
- 【转载】Ubuntu 12.04 LTS 中文输入法的安装
- 集群通信组件Tribes之整体介绍
- Java框架spring 学习笔记(三):Bean 的生命周期
- python全栈开发day85-查:数据表 数据头 增加列 展示多对多字段 反向解析编辑和删除按钮的url
- koa执行过程原理分析
- 001_linux下的log
- Axis2之Spring装配
- Spring mvc Json 的正确返回姿势
- 异步多线程 Thread ThreadPool Task
- LaTeX文章结构
热门文章
- 虚拟dom和diff算法
- 【转发】【composer】composer 命令行介绍
- python--第一类对象,函数名,变量名
- Memcached特性及优缺点
- UVa 10534 DP LIS Wavio Sequence
- Docker存储和网络
- Python算法-二叉树深度优先遍历
- Maven部署异常:on project standalone-pom: Cannot deploy artifact from the local repository解决方法
- 【深度学习一】tensorflow安装
- request,response,session,cookie,application