当我在同一个指针上使用不同的连续 calloc 函数时会发生什么?
int *ptr;
ptr = (int *) calloc(X, sizeof(int));
ptr = (int *) calloc(Y, sizeof(int));
ptr = (int *) calloc(Z, sizeof(int));
其中 X,Y,Z 是三个不同的值。
您将失去与先前分配的内存的连接,并且您将无法再释放它 - 内存泄漏
如果您失去释放它的方法,就会泄漏先前分配的内存。
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?