title: How do pointers assigned to pointers and free() work together?
body: <p>Why would freeing a pointer say p, which is assigned to where another pointer q points to, free q as well?</p>
  
  <pre><code>//for example,
  int *p = malloc(sizeof(int));
  *p = 10;
  int *q = malloc(sizeof(int));
  q = p;
  free(p);
  //This frees q as well.
  </code></pre>
  
  <p>Pointers q and p have different addresses but only point to the same location (i.e. to say that they store the same address which is of 10. Correct me if I'm mistaken there).</p>
  
  <p>The contradiction most definitely arises in the way I think about pointers or in the way free() works because from all that I know (which is not a lot), since q and p have different addresses, freeing p should not affect q at all, unless I am wrong in understanding pointers, or that free()/memory works in a peculiar way.</p>
  
  <p>I'd like to know why this is so.
  (I'm aware of the post <a href="https://stackoverflow.com/questions/29985497/free-an-assigned-pointer">Free an assigned pointer</a>, but it doesn't explain why or how exactly this happens)</p>