函数内 定义 static的问题
程序代码:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 static const char *msg[] = {"sunday", "monday", "tuesday", "wednesday", 5 "thursday", "friday", "saturday"}; 6 char *get_a_day(int index) 7 { 8 static char buf[20]; 9 strcpy(buf, msg[index]); 10 return buf; 11 } 12 13 int main(int argc, const char *argv[]) 14 { 15 printf("%s, %s\n", get_a_day(0), get_a_day(1)); 16 printf("%s, %s, %s\n", get_a_day(2), get_a_day(3), get_a_day(4)); 17 18 return 0; 19 }
程序运行结果是:sunday, sunday
:tuesday, tuesday, tuesday
求解释