#include<iostream>
#include<cstdio>
using namespace std;
void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
void swap2(int* p1, int* p2)
{
int temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
int main()
{
int a = 20;
int b = 19;
//值传递不会改变实参
swap(a, b);
cout << "a=" << a << endl;
cout <<"b=" << b << endl;
//地址传递会改变实参
swap2(&a, &b);
cout << a << endl;
cout << b << endl;
return 0;
}
指针和函数
最新推荐文章于 2024-10-06 10:17:48 发布