In C we learn that at the end of the program, in which we allocate memory dynamically, we need to free it otherwise there is a memory leakage.
#include <stdio.h>
int a = 17;
int main(void)
{
int b = 18; //automatic stack memory
int * c;
c = malloc( sizeof( int ) ); //dynamic heap memory
*c = 19;
printf("a = %d at address %x\n", a, &a);
printf("b = %d at address %x\n", b, &b);
printf("c = %d at address %x\n", *c, c);
free(c);
system("PAUSE");
return 0;
}
My question is that why do we need to do it manually? won't the memory get freed by itself when the program ends(like in the above example) ?