可能重複:
Why does this Seg Fault?
What is the difference between char a[] = 「string」; and char *p = 「string」;爲什麼這是錯的?
試圖瞭解爲什麼S [0] = 'H' 會失敗。我猜這與處理內存中的數據段有關,但也許有人更好地解釋這一點?
void str2 (void)
{
char *s = "hello";
printf("%s\n", s);
s[0] = 'H'; //maybe this is a problem because content in s is constant?
printf("%s\n", s);
}
int main()
{
str2();
return 0;
}
歡迎來到SO。除了重複之外,你的問題標題對於澄清你的內容也沒有多大幫助。 –
什麼是無意義的問題名稱! – onmyway133