void Swap1(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
void Swap2(int *x, int *y)
{
int *pTemp;
pTemp = x;
x = y;
y = pTemp;
}
void Swap3(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void Swap4(int &x, int &y)
{
int temp;
temp = x;
x = y;
y = temp;
}
本文详细介绍了使用C语言实现两个整数变量交换的四种不同方法:通过临时变量、使用指针、引用传递以及通过地址操作符。每种方法都有其适用场景及优缺点。
2万+

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



