昨天我在自制的“strcpy”函数上遇到了一点麻烦。它现在虽然有效,但我有点困惑!
char* a = "Hello, World!"; //Works
char b[] = "Hello, World!"; //Works also
strcpy(a, "Hello!"); //Segmentation fault
strcpy(b, "Haha!!"); //Works..
区别在哪里?为什么 char 指针会导致“分段错误”?
为什么这甚至行得通?:
char* a = "Haha"; //works
a = "LOL"; //works..