给字符串指针p分配空间后,strcpy拷贝字符串内容会写入错误
#include<stdio.h>
#include<string.h>
int main() {
char* p = (char *)malloc(sizeof(char)*100);
strcpy(p, "qwerasd");
return 0;
}
将p改为数组p
char p[100];
strcpy(p, "qwerasd");
编译就能通过
p指针明明都指向了一片空的内存,为什么无法拷入字符串?