int main() {
	double dx = 7.7;
	double dy = 9.9;
	swap_r(dx,dy);
	//swap_?(7.7,9.9);
	cout << dx << endl << dy << endl;
}
Example #2
0
int main()
{
	int x = 7;

	int y = 9;

	swap_r(x, y);                      // replace ? by v, r, or cr

	swap_r(7, 9);

	const int cx = 7;

	const int cy = 9;

	swap_r(cx, cy);

	swap_r(7.7, 9.9);

	double dx = 7.7;

	double dy = 9.9;

	swap_r(dx, dy);

	swap_r(7.7, 9.9);

	cout << x << ' ' << cx << ' ' << dx << '\n' << y << ' ' << cy << ' ' << dy;
}
Example #3
0
int main ()
{
  // integer
  int x=7;
  int y=9;
  cout << "Before the swap x = "<< x << ", y = "<<y <<endl;
  swap_r(x,y);
  cout << "After the swap x = "<< x << ", y = "<<y <<endl;
  // swap_r(7,9); // Need a variable to reference. Will not compile

  // const integer
  const int cx=7;
  const int cy=9;
  // swap_r(cx,cy); // Can not reference a constant. Will not compile
  // swap_r(7.7,9.9); // Need a variable to reference. Will not compile

  // double
  double dx=7.7;
  double dy=9.9;
  //swap_r(dx,dy); //  invalid initialization of reference of type ‘int&’ from expression of type ‘double’
  //swap_r(7.7,9.9); //  invalid initialization of reference of type ‘int&’ from expression of type ‘double’

  return 0;
}