#include <stdio.h>
char * fun();
int * fun2();
int main()
{
char *pp = fun();
printf("%c %c %c %c \n",*pp,*(pp+1),*(pp+2),*(pp+3),*(pp+4));
printf("%s\n",pp);
int *aa=fun2();
printf("%d %d %d %d\n",*aa,*(aa+1),*(aa+5),*(aa+9));
}
char * fun()
{
static char p[6]="hello";
printf("fun=%s \n",p);
}
int * fun2()
{
static int a[10] = {0,1,2,3,4,5,6,7,8,9};
return a;
}
在Linux编译pass, 运行时报警,如下:
co@ubuntu:/usr/cel$ gcc -o array array.c
co@ubuntu:/usr/cel$ ./array
fun=hello
Segmentation fault (core dumped)
co@ubuntu:/usr/cel$
慕尼黑8549860