title: Swapping two pointers
body: <p>I'm trying to write a function that takes two pointers as arguments and then makes the first pointer point to the object the second pointer was pointing to and the second to the object pointed to by the first.</p>
  
  <pre><code>void swap(int *x, int *y)
  {
      int *s;
      s = x;
      x = y;
      y = s;
  }
  </code></pre>
  
  <p>In the main function, I'll do something like</p>
  
  <pre><code>int x, y;
  swap(&amp;x, &amp;y);
  std::cout &lt;&lt; &amp;x &lt;&lt; " " &lt;&lt; &amp;y &lt;&lt; std::endl;
  </code></pre>
  
  <p>But it seems like the addresses don't change.</p>
  
  <p>If instead I dereference the pointers and try to change the values, the values are swapped as expected. I'm wondering why this function won't change where the pointers point to.</p>