Given the following line:
int *digits = (int *) malloc(3 * sizeof(int));
Say we store the values 1, 2 and 3 in locations, digits[0], digits[1], digits[2]. As follows:
digits[0] = 1;
digits[1] = 2;
digits[2] = 3;
If the following line is called:
free(++digits);
Is the entire memory range returned by malloc freed, or just the int sized block currently pointed to by digits - at that time, digits[1]? Or is the correct way, to free the entire range by iteration, i.e:
for (i = 0; i < 3; i++)
{
free(digits[i]);
}
I am trying to understand the range of a call to free. Is the entire memory chunk returned by malloc freed, or is only a sub-portion, currently referenced by the pointer digits freed?