free函数

free函数
原型: void free(void *ptr)
功 能: 释放ptr指向的存储空间。被释放的空间通常被送入可用存储区池,以后可在调用malloc、realloc以及calloc函数来再分配。
程序例:
#include <string.h>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
int main(void)
{
char *str;
/* allocate memory for string */
str = (char *)malloc(10);
if(str == NULL){
perror("malloc");
exit(1);
}
/* copy "Hello" to string */
strcpy(str, "Hello");
/* display string */
printf("String is %s ", str);
/* free memory */
free(str);
return 0;
}
原文地址:https://www.cnblogs.com/getyoulove/p/3945219.html