利用异或运算进行两个变量内容的交换,程序崩溃,求解~该如何解决
利用异或运算进行两个变量内容的交换,程序崩溃,求解~
交换程序为:
void inplace_swap(int *x,int *y)
{
*x = *x ^ *y;
*y = *x ^ *y;
*x = *x ^ *y;
}
void mian()
{
int *i=2,*j=3;
inplace_swap(i,j);
return ;
}
------解决方案--------------------
交换程序为:
void inplace_swap(int *x,int *y)
{
*x = *x ^ *y;
*y = *x ^ *y;
*x = *x ^ *y;
}
void mian()
{
int *i=2,*j=3;
inplace_swap(i,j);
return ;
}
------解决方案--------------------