#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *p(int n)
{
char s[] = "abcdefghij"; // 这个不能得到函数返回的字符串?这个就不会打印
// static char s[] = "abcdefghij"; //这个就可以打印
return s + n;
}
int main()
{
char *a = p(3);
printf("%s", a);
}
// 有无大佬讲解下是为什么
静态存储的变量的生存期是直到程序结束的
没有static修饰的局部变量,生存期在函数退出后就结束了
本回答被网友采纳