char* a = "Hello, World!";
gives a pointer to a string literal. A string literal can exist in read-only memory, so its contents cannot be changed.
char* a = "Haha";
changes the pointer a to point to another string literal. It does not try to modify the contents of the string literal, so it is safe / correct.
char b[] = "Hello, World!"
declares an array on the stack and initializes it with the contents of the string literal. The stack memory is written, so it is completely safe to change the contents of this memory.
source share