使用指针变量作形参,实现两个变量的值互换

 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 *p1,int *p2)
14 {
15     int temp;
16     temp=*p1;
17     *p1=*p2;
18     *p2=temp;
19 }

猜你喜欢

转载自www.cnblogs.com/borter/p/9401716.html
今日推荐