用传地址方法交换两个变量的值

来源:互联网 发布:复杂网络建模软件 编辑:程序博客网 时间:2024/04/27 22:55

#include<iostream>
 using namespace std;

void swap(int *,int *);
int main()
{
     int a=5;
     int b=10;
     swap(&a,&b);
     cout<<a<<endl<<b<<endl;

     return 0;
}

void swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}

原创粉丝点击