中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

C 庫函數(shù) - free()

C 標(biāo)準(zhǔn)庫 - <stdlib.h> C 標(biāo)準(zhǔn)庫 - <stdlib.h>

描述

C 庫函數(shù) void free(void *ptr) 釋放之前調(diào)用 calloc、malloc 或 realloc 所分配的內(nèi)存空間。

聲明

下面是 free() 函數(shù)的聲明。

void free(void *ptr)

參數(shù)

  • ptr -- 指針指向一個要釋放內(nèi)存的內(nèi)存塊,該內(nèi)存塊之前是通過調(diào)用 malloc、calloc 或 realloc 進(jìn)行分配內(nèi)存的。如果傳遞的參數(shù)是一個空指針,則不會執(zhí)行任何動作。

返回值

該函數(shù)不返回任何值。

實(shí)例

下面的實(shí)例演示了 free() 函數(shù)的用法。

實(shí)例

#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *str; /* 最初的內(nèi)存分配 */ str = (char *) malloc(15); strcpy(str, "json"); printf("String = %s, Address = %pn", str, str); /* 重新分配內(nèi)存 */ str = (char *) realloc(str, 25); strcat(str, ".com"); printf("String = %s, Address = %pn", str, str); /* 釋放已分配的內(nèi)存 */ free(str); return(0); }

讓我們編譯并運(yùn)行上面的程序,這將產(chǎn)生以下結(jié)果:

String = json,  Address = 0x7fe4e4c02b10
String = json.cn,  Address = 0x7fe4e4c02b10

C 標(biāo)準(zhǔn)庫 - <stdlib.h> C 標(biāo)準(zhǔn)庫 - <stdlib.h>

其他擴(kuò)展