首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

函数的局部变量解决思路

2013-12-20 
函数的局部变量#include stdio.h#include malloc.hstruct my{int a}struct my *f0(){struct my tmp

函数的局部变量
#include <stdio.h>
#include <malloc.h>
struct my
{int a;};

struct my *f0()
{struct my tmp;
 tmp.a = 1;
 return &tmp;
}

void main()
{
struct my *tmpp;

tmpp = f0();
printf("%d",tmpp->a);

}
在函数f0中定义了一个局部结构体变量tmp,然后返回其地址。在main函数中调用了f0,返回值赋值给了指针tmpp,我想问的是为什么下面的printf("%d",tmpp->a);能输出局部变量tmp的内部成员,为什么tmp这个局部变量在f0函数调用后没有被销毁?
[解决办法]
有可能被其他数据覆盖

热点排行