#include <stdio.h>
//str[]存在于getStr1的栈中,函数返回后就不存在了
char* getStr1()
{
char str[] = "hello world";
return str;
}
//*str存在于全局变量区中
char* getStr2()
{
char* str = "hello world";
return str;
}
//static变量存在于全局变量区中
char* getStr3()
{
static char str[] = "hello world";
return str;
}
int main()
{
char* p = getStr3();//只有getStr1不能满足要求
printf("%s\n",p);
return 0;
}
str[] , *str , static str[]的区别
最新推荐文章于 2023-01-19 14:38:03 发布