title: Reusing freed pointers in C
body: <p>There are many questions on this website regarding freeing pointers after use and, further, setting them to NULL. Arguments are fierce and the topic is seemingly divided equally. For example: <a href="/q/1879550">This question</a>. 
  I am confused about freeing pointers in general.</p>
  
  <p>Imagine you have a pointer to some memory space. After using the space, you free the pointer but do not set it to NULL. Later, you have another pointer that calls <code>malloc()</code>, or some analog, and it is allocated memory including the memory freed earlier (that the original pointer still points to). If this new pointer writes in this memory block, what happens? Intuitively nothing would happen, but the OP in the link provided earlier writes that it would crash the program.</p>
  
  <hr>
  
  <p><em>So my questions are:</em></p>
  
  <ol>
  <li><p>Given a freed pointer, what is keeping you from reassigning that pointer to a new memory location? Why is it 'bad' practice to reuse freed pointers? If calling <code>free(ptr)</code> only returns this memory to the OS, why can you not reassign the pointer so other memory locations and reuse it?</p>
  
  <pre><code>char *ptr = malloc(sizeof(*ptr)); //first allocation
  free(ptr); //release memory 
  ptr = NULL; 
  ptr = malloc(sizeof(*ptr)); //reallocate
  </code></pre></li>
  <li><p>Why would writing to a memory block that was previously freed, that still has the original pointer to it, cause the program to crash? --  See the first paragraph of the first post to the question linked above (if I misinterpreted the intent of this paragraph, please explain because it is not explicit whether that pointer is used again to write the memory or a new pointer is created.)</p></li>
  </ol>