/*Pointer Array (Dynamic) EXAMPLE*/
int size = 0;
printf("Enter the size of the array you want:\n");
scanf("%d",&size);
int * Dptr = malloc(sizeof(*Dptr)*size);
if(!Dptr)
return -1;
for(int i=0;i<size;i++)
Dptr[i]= -7;
printf("Congratulations, you successfully allocated and wrote to a dynamic array.\n");
free(Dptr); //how does it "know" what to deallocate? Is everything getting proprely reclaimed?
Above the a little doodle in C I wrote, I had a question about memory allocation concerning dynamic arrays. At the end I call the free function to deallocate the memory of the array I allocated, but my question is, how does it "know" how much memory to deallocate? Or, is it just deallocating the first int and leaving everything else dangling? If so, what is the proper way to reclaim this memory?