现在的位置: 首页 > 综合 > 正文

引用__简单的值交换

2018年04月29日 ⁄ 综合 ⁄ 共 227字 ⁄ 字号 评论关闭
# include<cstdio>
# include<iostream>

using namespace std;

void swap( int &a,int &b );

int main(void)
{
    int x = 8;
    int y = 10;
    cout<<"x="<<x<<"   y="<<y<<endl;
    swap( x,y );
    cout<<"x="<<x<<"   y="<<y<<endl;

    return 0;
}

void swap( int &a,int &b )
{//引用的使用
    int t;
    t = a;
    a = b;
    b = t;
}

抱歉!评论已关闭.