title: Why does a function operates on the copy of the actual parameters?
body: <p>I want to understand what is happening behind when you pass a parameter by value to a function. How is this "the function copy the values" done?</p>
  
  <p>I would like this to be a parallel between passing an array vs passing two variables.</p>
  
  <p>I've searched some threads, from which I consider <a href="https://stackoverflow.com/questions/10959694/why-does-call-by-value-example-not-modify-input-parameter">this</a> would best fit, although I have some other question.</p>
  
  <p>Here are two examples:</p>
  
  <p>Ex1:</p>
  
  <pre><code>void function(int arr[])
  {
      cout &lt;&lt; arr &lt;&lt; endl;                // The address of the first elm
      cout &lt;&lt; sizeof(arr);                // 4 (bytes size of address on 32 bit)
  }
  
  int main()
  {
      int vector[] = {1,2,3,4,5,6,7};
      function(vector);
      return 0;
  }
  </code></pre>
  
  <p>Ex2:</p>
  
  <pre><code>void interChange(int a, int b)
  {
      int tmp;
      tmp = a;
      a = b;
      b = tmp;
  }
  
  int main()
  {
      int a = 5, b = 3;
      interChange(a, b);
      return 0;
  }
  </code></pre>
  
  <p>In the first one, I want to show that even if I pass an array by value it is still interpreted as a pointer (allowing modifications in function to alter the actual <code>vector</code> values), this is why printing the array will output an address, and printing its size will output the dimension of a pointer.</p>
  
  <p>In the second example, the parameters are passed by value, but this time they do not alter the values of variables <code>a</code> and <code>b</code>. How does this process take place? Why are they copied instead of using their addresses too? Does the compiler take into account something about their addresses? If I print <code>&amp;a</code> in <code>main()</code> and then inside the interChange, I get two addresses very close one to each other E.g :<code>0x69fed8</code>, <code>0x69fe80</code>.</p>