同じポインターに対して異なる calloc 関数を連続して使用するとどうなりますか?
int *ptr;
ptr = (int *) calloc(X, sizeof(int));
ptr = (int *) calloc(Y, sizeof(int));
ptr = (int *) calloc(Z, sizeof(int));
X、Y、Z は 3 つの異なる値です。
以前に割り当てられたメモリへの接続が失われ、解放できなくなります - メモリリーク
解放する手段を失うと、以前に割り当てられたメモリがリークします。
変数に値を何度も代入した場合と同じことが起こりますint
(メモリ リークという追加の問題があります)。
int i;
i = 42;
i = 0; // where's the 42?
i = 1; // where's the 42? and the 0?
i = 42; // where's the 42? -- Oh! I see it! :) -- and the 0? and the 1?