话不多说,直接上干货
#include<iostream>
using namespace std;
//实现两个数字的交换
void swap01(int a, int b)
{
int temp = a;
a = b;
b = temp;
cout << "swap01-a = " << a << endl << "swap01-b = " << b << endl;
}
void swap02(int* p1, int* p2)
{
int temp = *p1;
*p1 = *p2;
*p2 = temp;
cout << "swap01-p1 = " << *p1 << endl << "swap01-p2 = " << *p2 << endl;
}
int main()
{
//值传递------改变地址不改变值
int a = 10;
int b = 20;
swap01(a, b);
cout << endl;
cout << endl;
cout << endl;
cout << "a = " << a << endl << "b = " << b << endl;
cout << "----------------------------------------" << endl;
cout << endl;
cout << endl;
cout << endl;
//地址传递
swap02(&a, &b);
cout << "a = " << a << endl << "b = " << b << endl;
system("pause");
}
多多关照不迷路哟!!!
谢谢