I have a small snippet. It is related with several malloc statements. Can somebody please explain.
#include <stdio.h>
#include <stdlib.h>
int main(){
char* ptr1 = (char*)malloc(10);
free(ptr1);
char* ptr2 = (char*)malloc(10);
free(ptr1);
char* ptr3 = (char*)malloc(10);
free(ptr1);
return 0;
}
What will happen to the snippet..? Will the malloc for ptr2 or ptr3 will allocate the same memory that has been freed by free(ptr1)
..
More importantly what will happen internally if I free a memory which is already freed.