Why changing string characters causes segmentation fault(core dumped):
char *str = \"string\"; str[0] = \'S\'; //segmentation fault(core dumped)
char *str = "string"; points to a read-only part of memory and because of that the string can't be changed.
char *str = "string";
You need to declare an array instead of a pointer which points to an array if you want to change the array like this
char str[] = "string";