For a long time I did not make serious C, and I would really like to get a brief explanation. The following code compiles and works fine on HP / UX. It compiles without warning in GCC 4.3.2 on Ubuntu (even with gcc -Wall), but segfaults when run on Linux.
Can someone explain why?
#include <stdio.h> int main() { char *people[] = { "Abigail", "Bob" }; printf("First: '%s'\n", people[0]); printf("Second: '%s'\n", people[1]); /* this segfaults on Linux but works OK on HP/UX */ people[1][0] = 'R'; printf("First: '%s'\n",people[0]); return(0); }
source share