作业帮 > 综合 > 作业

What is the output of the main function? Can you explain why

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 20:10:02
What is the output of the main function? Can you explain why?
char *GetMemory(void)
{
char p[] = “hello world”;
return p;
}

void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);}
程序中有点小问题.
结果是乱码.
因为数组存放在栈中,随着函数GetMemory执行完成,栈空间已经释放,被用作其他用途.当指针str指向已释放的数组时,其内容不确定,所以乱码