函数名: 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;
}