标签:col class int span out str note ++ ios
#include <iostream> using namespace std; //利用引用是相同空间实现 void ExChange(int &a1 , int &b1) { int nTemp = a1; a1 = b1; b1 = nTemp; } //不引用的话,新变量有自己的空间,不会交换数据。 void notExChange(int a1 , int b1) { int nTemp = a1; a1 = b1; b1 = nTemp; } //用指针来实现 void ExChangeB(int *a1 , int *b1) { int nTemp = *a1; *a1 = *b1; *b1 = nTemp; } int main() { int a = 12, b = 15; cout << "a: " << a << endl; cout << "b: " << b << endl; //ExChange(a,b); //notExChange(a,b); ExChangeB(&a,&b); cout << "a: " << a << endl; cout << "b: " << b << endl; system("pause"); return 0; }
标签:col class int span out str note ++ ios
原文地址:https://www.cnblogs.com/mohu/p/8963320.html