1:代码如下:
// 5.7.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void swap(int *a,int *b)
{
int tmp;
tmp=*a;
*a=*b;
*b=tmp;
}
void swap(int a,int b)
{
int tmp;
tmp=a;
a=b;
b=tmp;
}
void main()
{
int x,y;
int *p_x,*p_y;
cout << " input two number " << endl;
cin >> x;
cin >> y;
p_x=&x;p_y=&y;
cout<<"按指针传递参数交换"<<endl;
swap(p_x,p_y);//执行的是参数列表都为指针的swap函数
cout << "x=" << x <<endl;
cout << "y=" << y <<endl;
cout<<"按值传递参数交换"<<endl;
swap(x,y);
cout << "x=" << x <<endl;
cout << "y=" << y <<endl;
}
View Code
运行结果:
原文链接: https://www.cnblogs.com/lovemi93/p/7522051.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/259768
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!