#include <stdio.h>
#include <conio.h>
void test(char *p)
{
p = p + 1;
*p = 'a';
}
int main()
{
char *str = "Hello";
test(str);
printf("%s", str);
getch();
return 0;
}
当我运行此代码时,它会给出分段错误?为什么会这样。const 理论对我来说并不清楚……而如果我将 str 声明为 char str[],它就可以完成工作。它们不是基本相同的东西吗?