i was playing with malloc() and free() and i notice that free() is not deallocating the memory
i was expecting the program to terminate without displaying the output but it ran surprisingly and it displayed the output.Code:#include <stdio.h> #include <stdlib.h> int main(void) { double *pInt = (double *) malloc(7*sizeof(double)); free(pInt); for (int j = 0; j < 7; j++) { *(pInt + j) = j; } for (int k = 0; k < 7; k++) { printf("Element is %e at address %p\n",*(pInt+k),pInt+k); } getchar(); return 0; }
why is this so? maybe i don't know how free() works.
i ran this under dev-cpp btw.