Why do I get a segmentation fault when writing to a “char *s” initialized with a string literal, but not “char s[]”? The following code receives seg fault on line 2: char *str = "string"; str[0] = 'z'; // could be also written as *str="z" printf("%s\n", str); While this works perfectly... May 15, 2022 0 Comments