1. 在函数GetMem栈内定义个数组,将地址return给main函数的指针str
eg:char p[] = “hello world”;
char *GetMemory(void)
{
char p[] =“hello world”;
return p;
}
void Test(void)
{
char *str =NULL;
str = GetMemory();
printf(str);
}
str内容不一定,因为当函数GetMemory执行完毕,栈内变量销毁。“hello world”字符串属于栈内内容,如果将char *p = “hello world”,可以打印出hello world
2. 字符数组和字符指针的赋值
https://www.cnblogs.com/foreverW/p/6652657.html
1.字符数组只能在定义的时候赋值
char arr[]={"hello}或者“hello”;
2.字符串指针可以先定义后赋值
char *str;
str = “hello”;
或者char *str = “hello”;
https://www.cnblogs.com/beihaidao/p/5927229.html