动态脑电图多久出结果:关于指针的简单概念

来源:百度文库 编辑:神马品牌网 时间:2024/05/10 12:31:28
char a[] = “hello”;

int len = strlen(a);

char *p = (char *)malloc(sizeof(char)*(len+1));

strcpy(p, a);

if (strcmp(p, a) == 0)

cout<<p<<endl;

free(p);

上面的这句:
char *p = (char *)malloc(sizeof(char)*(len+1));
不知道到底分配了多大空间?为什么会这么写呢?哪位兄弟能否解答一下?

5+1个字节,五个字节为了存在 hello 的,另外一个为了存储字符串的结束符 '\0' 的