#include <stdio.h>
void swap(int *x, int *y)
{
*x = ((*x) ^ (*y));
*y = ((*x) ^ (*y));
*x = ((*x) ^ (*y));
}
int main()
{
int a,b;
a=2;b=3;
swap(&a,&b);
printf("%d,%d",a,b);
}
x=2^3;
y=8^3;
x=8^512;
所以,這個值交換了嗎?
uj5u.com熱心網友回復:
^不是冪函式,這個在C++里是按位異或,相同得0,不同得1x = 2,y = 3
x = 2^3 = 1
y = 1^3 = 2
x = 1^2 = 3
最終結果交換了。
uj5u.com熱心網友回復:
嗯,是我沒反應過來,這是按位異或
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/232774.html
標籤:其它技術問題
上一篇:Qt槽函式接收不到信號
