I read this on wikipedia
int main(void)
{
char *s = \"hello world\";
*s = \'H\';
}
When the program containing this code is com
When you do: char *s = "hello world";
then s
is a pointer that points to a memory that is in the code part, so you can't change it.
When you do: char s[] = "Hello World";
then s
is an array of chars
that are on the stack, so you can change it.
If you don't want the string to be changed during the program, it is better to do: char
const *s = ....;
. Then, when you try to change the string, your program will not crash with segmentation fault, it will arise a compiler error (which is much better).