Why can't I use this code to overwrite a string?

后端 未结 4 906
刺人心
刺人心 2020-12-11 11:50

Code:

#include \"stdio.h\"
#include \"string.h\"

int main()
{
  char *p = \"abc\";
  printf(\"p is %s \\n\", p);
  return 0;
}

O

4条回答
  •  甜味超标
    2020-12-11 12:17

    p is basically just a pointer to read-only data (which is "abc" in your case). You cannot overwrite that with "def".

提交回复
热议问题