# include iostreamusing namespace std;void Swap(int *pa, int *pb) { int t = *pa; *pa = *pb; *pb = t; cout "*pa = " *pa endl; }void Swap(int a, int b) { int tmp; tmp = a; a = b; b = tmp; cout "tmp = " tmp endl; }int main(){ int a = 3, b = 5;
# include <iostream> using namespace std; void Swap(int *pa, int *pb) { int t = *pa; *pa = *pb; *pb = t; cout << "*pa = " << *pa << endl; } void Swap(int &a, int &b) { int tmp; tmp = a; a = b; b = tmp; cout << "tmp = " << tmp << endl; } int main() { int a = 3, b = 5; Swap(&a, &b); /*执行第一个*/ Swap(a, b); /*执行第二个*/ printf("a = %d""; b = %d\n", a, b); cout << "a = " << a << "; b = " << b << endl; return 0; }
输出结果