title: Swap function using void pointers
body: <p>I want to make a swap function that can be generically used for any data type. I know that the following function works for ints:</p>
  
  <pre><code>void swap(void *a, void *b)
  {
      int temp;
      temp = *(int*)a;
      *(int*)a = *(int*)b;
      *(int*)b = temp;
  }
  </code></pre>
  
  <p>and this works for strings:</p>
  
  <pre><code>void swap(void *a, void *b)
  {
      void *temp;
      temp = *(void**)a;
      *(void**)a = *(void**)b;
      *(void**)b = temp;
  }
  </code></pre>