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就是随机值
浙公网安备 33010602011771号