title: free() : invalid pointer and how to reuse a currently freed pointer
body: <p>I want to address my pointer to another object and free the memory of previous object. This is what I did but I had a invalid pointer error. What is the right way to do it?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char const *argv[])
  {
      int number = 5;
      int number2 = 10;
  
      // Give memory manually 
      int *pointer2number = (int *) malloc(sizeof(int));
      pointer2number = &amp;number;
  
      printf("Number is %i\n", number);       
      printf("Address of number is %p\n", pointer2number);
  
      // Free memory 
      free(pointer2number);
      pointer2number = (int *) malloc(sizeof(int));
      pointer2number = &amp;number2;
      printf("New number is %i\n", *pointer2number);
      return 0;
  }
  </code></pre>