最好还能举几个例子以及每行的说明~谢谢啦

热心网友

函数名: calloc 功 能: 分配主存储器 用 法: void *calloc(size_t nelem, size_t elsize); 程序例: #include #include int main(void) { char *str = NULL; /* allocate memory for string */ str = calloc(10, sizeof(char)); /* copy "Hello" into string */ strcpy(str, "Hello"); /* display string */ printf("String is %s\n", str); /* free memory */ free(str); return 0; } 函数名: free 功 能: 释放已分配的块 用 法: void free(void *ptr); 程序例: #include #include #include int main(void) { char *str; /* allocate memory for string */ str = malloc(10); /* copy "Hello" to string */ strcpy(str, "Hello"); /* display string */ printf("String is %s\n", str); /* free memory */ free(str); return 0; } 函数名: malloc 功 能: 内存分配函数 用 法: void *malloc(unsigned size); 程序例: #include #include #include #include int main(void) { char *str; /* allocate memory for string */ /* This will generate an error when compiling */ /* with C++, use the new operator instead。 */ if ((str = malloc(10)) == NULL) { printf("Not enough memory to allocate buffer\n"); exit(1); /* terminate program if out of memory */ } /* copy "Hello" into string */ strcpy(str, "Hello"); /* display string */ printf("String is %s\n", str); /* free memory */ free(str); return 0; } 函数名: realloc 功 能: 重新分配主存 用 法: void *realloc(void *ptr, unsigned newsize); 程序例: #include #include #include int main(void) { char *str; /* allocate memory for string */ str = malloc(10); /* copy "Hello" into string */ strcpy(str, "Hello"); printf("String is %s\n Address is %p\n", str, str); str = realloc(str, 20); printf("String is %s\n New address is %p\n", str, str); /* free memory */ free(str); return 0; } 。

热心网友

malloc()和free()对应,用了malloc申请的记得要用free释放掉

热心网友

void * malloc(unsigned size); 动态分配size字节空间,返回它的指针void * calloc(unsigned n,unsigned size);动态分配n个连续的size字节空间,返回第一个指针,好比一个数组void free(void *) ; 释放上述两函数分配的空间;void * realloc(void *p,unsigned n);将p指向的内存空间扩展成n个,把它放在最后解释因为偶不建议你使用~~确实要用也要考虑多种情况

热心网友

老大,也太节约了,教育是要投资的买本C的书看不是更有把握些