title: Double argument to int parameter and int& parameter
body: <p>Firstly, this is an exercise question from the book &quot;Programming, Principles and Practice Using C++&quot;. The books purposely told me to write these functions to understand why some of the lines cause problems. So changing the code is not an option.</p>
  <p>I am able to send double variables or double literals as arguments to swap_v function that uses pass by value (int parameters).</p>
  <p>I am not able to send double variables or double literals as arguments to swap_r function that uses pass by reference (int&amp; parameters). It works when I use pass by value.</p>
  <p>Both lines give these 3 errors.</p>
  <p>1- a reference of type &quot;int &amp;&quot; (not const-qualified) cannot be initialized with a value of type &quot;double&quot;</p>
  <p>2- initial value of reference to non-const must be an lvalue</p>
  <p>3- 'void swap_r(int &amp;,int &amp;)': cannot convert argument 1 from 'double' to 'int &amp;'</p>
  <pre><code>#include &lt;iostream&gt;
  
  void swap_v(int a, int b)
  {
      int temp;
      temp = a;
      a = b;
      b = temp;
  }
  
  void swap_r(int&amp; a, int&amp; b)
  {
      int temp;
      temp = a;
      a = b;
      b = temp;
  }
  
  int main()
  {
      /*
      int x = 7;
      int y = 9;
      swap_v(x, y); // Doesnt swap
      swap_v(7, 9); // Cant swap literals.
  
      const int cx = 7;
      const int cy = 9;
      swap_v(cx, cy); // Doesnt swap
      swap_v(7.7, 9.9); // Cant swap literals.
  
      double dx = 7.7;
      double dy = 9.9;
      swap_v(dx, dy); // Doesnt swap
      swap_v(7.7, 9.9); // Cant swap literals.
      */
  
      int x = 7;
      int y = 9;
      swap_r(x, y); // Swaps
      // Doesnt compile. You have to pass variables when using pass by reference.
      //swap_r(7, 9);
  
      const int cx = 7;
      const int cy = 9;
      // Doesnt compile. You cant change constant values.
      //swap_r(cx, cy);
      // Doesnt compile. You have to pass variables when using pass by reference.
      //swap_r(7.7, 9.9);
  
      double dx = 7.7;
      double dy = 9.9;
      // ???
      swap_r(dx, dy);
      // ???
      swap_r(7.7, 9.9);
  }
  </code></pre>