C noob在这里.当我以后可以传递任何大小的字符串时,我给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;
}
Run Code Online (Sandbox Code Playgroud)
这很好用.我原本以为我无法在我对malloc应该是什么的理解中存储超过1个字符串.