malloc函数面试题2

char* GerMemory(void)
{
char p[] = "hello world";
return p;
}

void Test(void)
{
char* str = NULL;
str = GerMemory();
printf(str);
}
int main()
{
Test();
return 0;

 

解析:乱码

返回栈空间的地址问题

 当str=GetMemory();后 函数调用完毕,p内存被系统收回,再次打印str就是随机值

posted @ 2022-05-09 22:28  藏进夜里躲在光下  阅读(43)  评论(0)    收藏  举报