title: Swap integers using pointers
body: <p>Consider the function :</p>
  
  <pre><code>void swap (int *p,int *q)
  {
      int temp;
      temp=*p;
      *p=*q;
      *q=temp;
  }
  </code></pre>
  
  <p><code>swap(4 , 5)</code></p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>5    4
  </code></pre>
  
  <p>I am aware that this is the right way to swap two integers using pointers, as mentioned in the books. But what is actually going on in there? It's very confusing. Consider this function , where the step *p=*q is replaced by p=q i.e., with the indirection operator * removed .</p>
  
  <pre><code>void swap (int *p,int *q)
  {
      int temp;
      temp=*p;
      p=q;
      *q=temp;
  }
  </code></pre>
  
  <p>Now ,what would happen? In this case the output i get for </p>
  
  <p><code>swap(4 , 5)</code></p>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>4    4
  </code></pre>