Hi. Below are two pieces of code. This first one works fine:
char str[] = "Hello World";
char *b;
b = &(str[3]);
*b = '3';
printf("%s\n", str);
However this second one results in a segmentation fault.
char *str = "Hello World";
char *b;
b = &(str[3]);
*b = '3';
printf("%s\n", str);
The difference is in the definition of the variable str. Why does one method work fine and the other result in a segmentation fault? When is it best to use a str[] definition and the *str definition?