free関数 - 確保したメモリを解放する
free関数で、確保したメモリ領域を解放できます。stdlib.hヘッダをインクルードする必要があります。
#include <stdlib.h> void free(void *ptr);
free関数のサンプル
free関数を使ってメモリを開放するサンプルです。
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main(void) {
// 動的なメモリの確保
int32_t length = 4;
int32_t* nums = calloc(sizeof(int32_t), capacity);
// 処理
// 不要になったらfreeで解放
free(bytes);
}
C言語ゼミ


