Hi everyone,

I'm going to explain why it is recommended to use const modifier when declaring and initializing a char pointer to a string literal:

Let's declare and initialize a char pointer to string literal first:

Code:
char *ptr = "Sound!";
What will happen if we try to update or alter the string literal "Sound!"?
Well, some compilers don't allow updating string literal with char pointer, but let's assume that we are working on a complier that allow this.

I'll update the first character of the string literal as below:
Code:
ptr[0] = 'R'; // now the string literal is updated to "Round!" instead of "Sound!"
Let's print out the string literal "Sound!" by itself and see what we will get!
Code:
printf("Sound!"); // This will output "Round!"
The reason is for getting the output "Round!" instead of the "Sound!" is the UNDEFINED BEHAVIOR of the compiler.
All identical literal strings will be represented by a single copy in memory by the compiler. therefore such behavior could lead to memory access errors.

The compiler stores the Literal String in "Read Only Memory Segment" and should not be edited or updated.
So, it is recommended to use the const modifier when using char pointer to literal string:

Code:
 const char *ptr = "Sound!";
If you need to update the literal string, you can use char array instead, and you should have no problem with that, since the array gets a copy of literal string and can be updated. unless if you declare it as a const.

I hope you find this useful.