title: Confusion with weird C pointer behavior when passing through functions
body: <p>I have a function int_make, which I use to convert int's into void pointers:</p>
  
  <pre><code>void* int_make(int id_num){
     int* id_ptr = malloc(sizeof(int));
     id_ptr = &amp;id_num;
     void* id = id_ptr;
  return id;}
  </code></pre>
  
  <p>I test this in main by the following</p>
  
  <pre><code>void * num_ptr = int_make(889);
  printFunction(num_ptr);
  </code></pre>
  
  <p>where printFunction(num_ptr) casts the pointer to an int* pointer, then dereferences it</p>
  
  <pre><code>void printFunction(void * num_ptr){
  printf("*(int*)num_ptr is %d\n", *(int*)num_ptr);}
  </code></pre>
  
  <p>and I get expected output</p>
  
  <pre><code>*(int*)num_ptr is 889
  </code></pre>
  
  <p>All good, until I call a different function, testD, (ignore unused parameters, all nonbuggy code has been removed)</p>
  
  <pre><code>void testD(void* ID, void* name, void* address, void* phone, struct hashtable* hashtable){
     printf("*(int*)phone is %d\n", *(int*)phone);}
  </code></pre>
  
  <p>the call in main:</p>
  
  <pre><code>void* phone= int_make(939209);
  testD(id,name,addy,phone, table);
  </code></pre>
  
  <p>where I get the confusing result:</p>
  
  <pre><code>*(int)phone is 21985
  </code></pre>
  
  <p>This number (21985) is different every time I execute the code, so it must be a memory location, although I have no idea why my strategy (void* to int) worked on the 889 example (and many other tests, each rerun several times) and not this one.</p>