I have a question about a double pointer in C. For example:
int** point = malloc(sizeof(int**));
int* point2 = malloc(sizeof(int*));
*point2 = 5;
*point = point2;
free(point2);
printf("%d", *point);
My question is, if I have a double pointer pointing to another pointer (point2) and I make a free on (point2), the double pointer (point) is going to point to a memory address that has nothing. So I should do * point = NULL?
int* point2 = malloc(sizeof(int*));point2 is an integer pointer; it should point to an int. So, you should allocatesizeof(int), orsizeof *point2int* point = malloc(sizeof(int))this is what @wildplasser means, I thinkint **point = malloc(sizeof *point)andint *point2 = malloc(sizeof *point2)to avoid these errors.double*.