亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

C 語(yǔ)言基礎(chǔ)教程

C 語(yǔ)言流程控制

C 語(yǔ)言函數(shù)

C 語(yǔ)言數(shù)組

C 語(yǔ)言指針

C 語(yǔ)言字符串

C 語(yǔ)言結(jié)構(gòu)體

C 語(yǔ)言文件

C 其他

C 語(yǔ)言參考手冊(cè)

C 庫(kù)函數(shù) free() 使用方法及示例

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

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

聲明

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

void free(void *ptr)

參數(shù)

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

返回值

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

在線示例

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

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

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

String = nhooo,  Address = 0x7fe4e4c02b10
String = (cainiaoplus.com),  Address = 0x7fe4e4c02b10

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