Loose-Info.com
Last Update 2012/07/05
TOP - C言語 - stdlib.h - free()

引数のポインタにより参照されるメモリの割り当てを取り消します。

free(  引数1  )

引数1 :
void *
確保されたメモリ領域を参照するポインタ

(例)
#include <stdio.h> #include <stdlib.h> int main() { int i; char *pc = (char *)malloc(20); if (pc != NULL) { for (i=0; i<10; i++) { *(pc+i) = i + 0x30; } *(pc+i) = '\0'; for (i=0; i<10; i++) { printf("[%d] : %c\n", i, *(pc+i)); } printf("%s\n", pc); free(pc); } else { printf("確保失敗\n"); } return 0; }

実行結果
[0] : 0 [1] : 1 [2] : 2 [3] : 3 [4] : 4 [5] : 5 [6] : 6 [7] : 7 [8] : 8 [9] : 9 0123456789