#include <stdio.h> #include <string.h> int main(void) { char *name[]={ "Illegal day", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; printf("hos = %s \n", name[0]); printf("hos = %s \n", name[1]); printf("hos = %s \n", name[3]); strncpy(name[0],"Illegal",7); printf("host = %s \n", name[0]); printf("host = %s \n", name[1]); printf("host = %s \n", name[3]); } [root@localhost 99]# ./test hos = Illegal day hos = Monday hos = Wednesday Segmentation fault ==》
尚方宝剑之说