Reputation: 5833
What happens when I use different succesive calloc functions over the same pointer?
int *ptr;
ptr = (int *) calloc(X, sizeof(int));
ptr = (int *) calloc(Y, sizeof(int));
ptr = (int *) calloc(Z, sizeof(int));
Where X,Y,Z are three distinct values.
Upvotes: 2
Views: 657
Reputation: 108978
The same thing that happens when you assign a value to an int
variable over and over again (with the extra problem of leaking memory)
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?
Upvotes: 2
Reputation: 96139
You will lose the connection to the previously allocated memory and you will no longer be able to free it - a memory leak
Upvotes: 8
Reputation: 182664
You leak the previously allocated memory if you lose the means to free it.
Upvotes: 3