free

C語言提供的庫函數

目錄

正文


原型: void free(void *ptr)
功 能: 釋放ptr指向的存儲空間。被釋放的空間通常被送入可用存儲區池,以後可在調用malloc、realloc以及calloc函數來再分配。
程序例:
#include
#include
#include
#include
int main(void)
{
char *str;
str = (char *)malloc(10);
if(str == NULL){
perror("malloc");
exit(1);
}
strcpy(str, "Hello");
printf("String is %s\n", str);
free(str);
return 0;
}