title: Simple C++ swap function
body: <p>Why is it that if I have a function like this, to swap two numbers, it doesn't work[swap], (I know I can do this by declaring pointers in the prototype, and then pass the address of the respective variables in main()), but works for array, without having to pass pointers and addresses.</p>
  
  <p>Doesn't work</p>
  
  <pre><code>void num_exchange(int m, int n);
  
  int main(){
  
  int num1 = 5;
  int num2 = 6;
  
  num_exchange(num1 , num2 );
  
  cout &lt;&lt; "num1 =" &lt;&lt; num1 &lt;&lt; endl;
  cout &lt;&lt; "num2 =" &lt;&lt; num2 &lt;&lt; endl;
  
  return 0;
  }
  
  void num_exchange(int m, int n){
  int temp;
  temp = m;
  m = n;
  n = temp;
  }
  </code></pre>
  
  <p>Works</p>
  
  <pre><code>void arr_exchange(int [], int);
  
  int main(){
  
  
  int n[7] = { 0, 0, 0, 0, 0, 0, 0 };
  
  arr_exchange(n, 7);
  for (int i = 0; i &lt; 7; i++)
      cout &lt;&lt; n[i] &lt;&lt; " ";
  
  return 0;
  }
  
  void arr_exchange(int x[], int){
  for (int i = 0; i &lt; 7; i++)
      x[i] = 1;
  }
  </code></pre>