複製鏈接
請複製以下鏈接發送給好友

free

(C語言提供的庫函數)

鎖定
free,指的是一種C語言提供的庫函數,用於釋放ptr指向的存儲空間。
外文名
free
原    型
void free(void *ptr)
原型: 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\n", str);
/* free memory */
free(str);
return 0;
}