#include"iostream"
using namespace std;
const int N = 8;
int main()
{
void s(int &a, int &b);
int i = 3, b = 5;
s(i, b);
system("pause");
return 0;
}
void s(int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
引用: 双向传递!
#include"iostream"
using namespace std;
const int N = 8;
int main()
{
void s(int *a, int *b);
int i = 3, b = 5;
s(&i, &b);
system("pause");
return 0;
}
void s(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
地址传递。 注意: 存储空间的区别。
#include"iostream"
using namespace std;
const int N = 8;
int main()
{
void s(int a, int b);
int i = 3, b = 5;
s(i, b);
system("pause");
return 0;
}
void s(int a, int b)
{
int temp;
temp = a;
a =b;
b=

本文探讨了C++中函数参数的传递方式,包括值传递无法实现双向传递的问题,以及如何通过地址传递和引用实现双向数据交换。
3126

被折叠的 条评论
为什么被折叠?



