#include<stdlib.h>
#include<stdio.h>
char*GetMemory(void)
{
char p[] = "hello world";//当把p返回给str后数组就生命周期结束,指向该地址的内容就随机了
return p;
}
void Test(void)
{
char* str = NULL;
str = GetMemory();
printf(str);
}
int main()
{
Test();//会越界访问
return 0;
}
标签:返回,void,char,Test,地址,str,空间,include,GetMemory
From: https://blog.51cto.com/u_16425777/9135054