title: Allocating memory for one dimensional array in C
body: <p>I have a question in regards to creating a dynamic array. </p>
  
  <pre><code>int *p; 
  p = malloc( 3 * sizeof( int ) );
  
  // initializes elements in the array
  for ( int i = 0; i &lt; 3; ++i ) {
      *p++ = i * 4;
  }
  </code></pre>
  
  <p>how can i free the memory i just allocated? for some reason, i find much easier deallocating a two dimensional array than one LOL. It's been along time since the last time i used C.</p>
  
  <p>if i do the following:</p>
  
  <pre><code>free( p ); // will probably get an error. 
  </code></pre>
  
  <p>Another thing in regards to pointers. I tried this:</p>
  
  <pre><code>int * p = malloc( sizeof( int ) );
  *p = 4;
  
  printf( "%d\n", *p ) // prints 4 as expected
  
  free( p );
  printf( "%d\n", *p ) // still prints the number 4!!!
  </code></pre>
  
  <p>the free function should release the block of memory that p points to. how is it that printf stills prints 4 then?</p>