【发布时间】:2014-07-18 23:47:37
【问题描述】:
关于我的问题下面的代码是因为“ptr”在本地块中。那么它如何在功能块之外访问。应该被限制 不是吗?就像一个正常的变量。我们正在尝试访问另一个函数的内存位置。
int * add(int a, int b){
// local pointer variable
int *ptr=NULL,c=0;
c = a+b;
ptr = &c;
return ptr;
}
int main()
{
// calling add function and accessing
// the value received using reference(*).
printf("%d",*add(2,3));
}
【问题讨论】:
标签: c pointers memory memory-management scope