C指標錯誤

jiangzhengdong發表於2013-03-07
int main (void)
{  
  char* string = "Hello World!";

  printf ("%s\n", string);
  replace_char(string, 10, 'a');
  printf ("%s\n", string);
}

void replace_char(char str[], int n, char c)
{
  str[n] = c;
}

這段程式碼執行將會出錯,因為string為char  const*型別


例子來源:http://stackoverflow.com/questions/7590098/replace-a-character-in-a-char-from-a-function

相關文章