2

同じポインターに対して異なる 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 つの異なる値です。

4

3 に答える 3

7

以前に割り当てられたメモリへの接続が失われ、解放できなくなります - メモリリーク

于 2011-10-12T15:24:08.417 に答える
3

解放する手段を失うと、以前に割り当てられたメモリがリークします。

于 2011-10-12T15:23:49.760 に答える
2

変数に値を何度も代入した場合と同じことが起こります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?
于 2011-10-12T15:27:15.673 に答える