要求将变量的值互换
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 int main(int argc, char** argv) { 6 void swap(int,int); 7 int i=3,j=5; 8 swap(i,j); 9 cout <<i<<" "<<j<<endl; 10 return 0; 11 } 12 13 void swap(int a,int b) 14 { 15 int temp; 16 temp=a; 17 a=b; 18 b=temp; 19 cout <<a<<" "<<b<<endl; 20 }