417.cpp

来自「C++实训教程」· C++ 代码 · 共 34 行

CPP
34
字号
//417.cpp  Swap.cpp function overload
#include <iostream.h>
void Swap(int& x,int& y);
void Swap(float& x,float& y);
void Swap(char& x,char& y);
void main(void)
{
	int n1 = 1, n2 = 2;
	Swap(n1,n2);
	cout << n1 << "  " << n2 << endl;
	float f1 = 1.11, f2 = 1.22;
	Swap(f1,f2);
	cout << f1 << "  " << f2 << endl;
	char c1 = 'A', c2 = 'B';
	Swap(c1,c2);
	cout << (char)c1 << "  " << (char)c2 << endl;
}
void Swap(int& x,int& y)
{
	int t = x;	x = y;	y = t;
}
void Swap(float& x,float& y)
{
	float t = x;	x = y;	y = t;
}
void Swap(char& x,char& y)
{
	char t = x;	x = y;	y = t;
}
/*
2  1
1.22  1.11
B  A
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?