新手问一段代码
程序代码:
#include "stdafx.h" #include <string.h> #include <stdlib.h> #include <iostream> using namespace std; int main(int argc, char* argv[]) { char a[] = "abc"; int n = strcmp(a,"abc"); cout<<n<<endl; strcpy(a,"def"); cout<<a<<endl; char* b = (char*)malloc(strlen(a)+strlen("abc")+1); strcpy(b,a); strcat(b,"abc"); cout<<b<<endl; return 0; } 请问为什么将里面的char a[] = "abc"换成char* a = "abc",运行时会发生内存不能为written的错误?