gpt4 book ai didi

c - 我给 malloc 什么参数有什么关系?

转载 作者:太空宇宙 更新时间:2023-11-04 01:00:43 27 4
gpt4 key购买 nike

<分区>

C 菜鸟在这里。当我稍后可以将任何大小的字符串传递给 malloc 时,我给 malloc 什么参数有什么关系?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
char *str;
str = malloc(1*sizeof(char));
strcpy(str, "abcd");
printf(str);
printf("\n");

return 0;
}

这很好用。根据我对 malloc 应该是什么的理解,我原以为我不能在 str 中存储超过 1 个字符。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com