title: Confusion about pointers and references in C++
body: <p>I have a bunch of code like this:</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  void swap(int *a, int *b) {
      int temp = *a;
      *a = *b;
      *b = temp;
  }
  
  int main() {
      int a;
      int b;
      a = 7;
      b = 5;
      swap(a, b);
      cout &lt;&lt; a &lt;&lt; b;
  
      return 0;
  }
  </code></pre>
  <p>This code does the swapping process as what I exactly wanted to swap 2 numbers, but when I want two numbers from the user as follows;</p>
  <pre><code>int a;
  int b;
  cin &gt;&gt; a;
  cin &gt;&gt; b;
  swap(a, b);
  cout &lt;&lt; a &lt;&lt; b;
  </code></pre>
  <p>the compiler gives me an error about <code>int</code> to <code>int*</code> error which is as expected. Why does the first code do the right swapping although I didn't use the method with <code>&amp;</code> operator?</p>