请输入您要查询的百科知识:

 

词条 free()
释义

函数名: free

功 能: 与malloc()函数配对使用,释放malloc函数申请的动态内存。(另:如果p 是NULL 指针,那么free 对p 无论操作多少次都不会出问题。如果p 不是NULL 指针,那么free 对p连续操作两次就会导致程序运行错误。)

用 法: void free(void *ptr);

程序例:

#include <string.h>

#include <stdio.h>

#include <alloc.h> //or #include <malloc.h>

int main(void)

{

char *str;

/* allocate memory for string */

str = (char *)malloc(10);

/* copy "Hello" to string */

strcpy(str, "Hello");

/* display string */

printf("String is %s\", str);

/* free memory */

free(str);

return 0;

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/7 16:27:02