当我尝试编译以下 C 代码时,出现总线错误。我猜这与我调用 memcpy 的方式有关,但我无法弄清楚。任何帮助将不胜感激!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *p = (char*)malloc(sizeof(char)*11);
// Assign some value to p
p = "hello";
char *name = (char*)malloc(sizeof(char)*11);
// Assign some value to name
name = "Bye";
memcpy (p,name,sizeof(char)*10); // Problem begins here
return 0;
}