本文主要是介绍Answer's Question about pointer,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
}
这篇关于Answer's Question about pointer的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!