void DoesSomething(int *first, int *second)
{
*first = *second - *first;
*second = *second - *first;
*first = *second + *first;
}
就是first和second互相交换
void DoesSomething(int *first, int *second)
{
int tmp = *first;
*first = *second;
*second = tmp;
}
交换两个数,卖弄技巧?
void DoesSomething(int *first, int *second)
{
*first = *first ^ *second;
*second = *first ^ *second;
*first = *first ^ *second;
}
不过玩弄技巧一定要注意整数上下溢出的问题,避免弄巧成拙。