After watching section on "Dynamically allocated memory" (from Week 4) several times, I still have a question unanswered. Consider the following code-
// Allocates 4 bytes of memory on heap and returns its address to pointer "px" which is created on stack //(the pointer "px" occupying memory on stack //which can vary from 4 to 8 bytes depending on compiler, as said during one of the lectures) int* px = malloc(sizeof(int); // assigns value "3" to the block of memory at which "px" is pointing. *px = 3; // frees up the block of memory to which px was pointing. free();
And now if we try-
*px = 4;
We gets, as expected a seg fault. That confirms that the memory block allocated on heap has been freed, BUT what happens to the memory which our pointer "px" was occupying on stack?