title: In C++, does Function declaration play a role in the way function parameters are passed - either by reference or by Value
body: <p>I understand without <strong>&amp;,</strong> the values are passed by value. Consider the following code snippet:</p>
  <pre><code>void swap(int x, int y)
  {
      int tmp = x;
      x = y; 
      y = tmp;
  }
  
  
  int main()
  {
      int a=10, b=20;
      swap(a,b);
      cout &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; b &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  <p>The output will be : 10 20</p>
  <p>However if the swap function is placed after the main function and there is no function declaration before the main. That is...</p>
  <pre><code>
  int main()
  {
      int a=10, b=20;
      swap(a,b);
      cout &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; b &lt;&lt; endl;
      return 0;
  }
  
  void swap(int x, int y)
  {
      int tmp = x;
      x = y; 
      y = tmp;
  }
  
  </code></pre>
  <p>In this case the output is going to be : 20 10.</p>
  <p>Shouldn't the o/p also be 10 20 in the second case. Can someone please help me to understand as to ow is pass by reference happening here?</p>