title: How do I correctly use a void pointer in C?
body: <p>Can someone explain why I do not get the value of the variable, but its memory instead?</p>
  
  <p>I need to use void* to point to "unsigned short" values.</p>
  
  <p>As I understand void pointers, their size is unknown and their type is unknown.<br>
  Once initialize them however, they are known, right?</p>
  
  <p>Why does my printf statement print the wrong value?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  void func(int a,  void *res){
      res = &amp;a;
      printf("res = %d\n", *(int*)res);
      int b;
      b = * (int *) res;
      printf("b =%d\n", b);
  }
  
  
  int main (int argc, char* argv[])
  {
      //trial 1
      int a = 30;
      void *res = (int *)a;
      func(a, res);
      printf("result = %d\n", (int)res);
      //trial 2
      unsigned short i = 90;
      res = &amp;i;
      func(i, res);
      printf("result = %d\n", (unsigned short)res);
      return 0;
  }
  </code></pre>
  
  <p>The output I get:</p>
  
  <pre><code>res = 30
  b =30
  result = 30
  res = 90
  b =90
  result = 44974
  </code></pre>