title: memcpy and pointers
body: <p>I am confuse on how to read the pointers copied in an array using memcpy.
  Following is what I have tried, but does not work.</p>
  
  <p>Basically, I have allocated block of memory in which I am copying pointers similar to array fashion, but during retrial it is not working. While this works with basic data types properly </p>
  
  <p>I want to store anything in the <code>element</code> block, It can be either <code>integers</code> or <code>pointers</code>.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #define INDEX(x)  ((char *)elements + (sizeof(int*) * (x)))
  int size = 10;
  
  void f2_int_ptr() {    
      int i = 0;
      void *elements = (void*)malloc(size * sizeof(int*));
      for ( i = 0; i &lt; size; i++ ) { 
         int *v = ( int *) malloc ( sizeof(int));
         memcpy ( v, &amp;i, sizeof ( int ));
  
  
         memcpy ( INDEX(i) , v,  sizeof (int*));
      }
      for ( i = 0; i &lt; size; i++ ) { 
          int *v = (int*)0;
          memcpy ( v, INDEX(i), sizeof(int *));
          printf ( "%d\n", *v );
      }
  }
  void f1_int() {
      int i = 0;
      void *elements = (void*)malloc(size * sizeof(int));
      for ( i = 0; i &lt; size; i++ ) { 
         memcpy ( INDEX(i) , &amp;i,  sizeof (int));
      }
      for ( i = 0; i &lt; size; i++ ) { 
          int v;
          memcpy ( &amp;v, INDEX(i), sizeof ( int ));
          printf ( "%d\n", v );
      }
  }
  int main(){
      f1_int();
      f2_int_ptr();
      return 0;
  }
  </code></pre>
  
  <p>In the above code <code>f1_int</code> works fine but <code>f2_int_ptr</code> does not work.</p>