请问有人能够解释一下下面代码中的 XOR
,(^)
到底是什么意思,以及为什么这个函数是一个指针吗?
char *strReverse(char *str)
{
char *pb, *pe;
for (pb = str, pe = str + strlen(str) - 1; pe > pb; ++pb, --pe)
{
*pb ^= *pe;
*pe ^= *pb;
*pb ^= *pe;
}
return str;
}
std::swap
会表现更好。这篇文章介绍了如何使用异或操作来交换两个变量的值。但是需要注意的是,使用 C++ 中的std::swap
函数能获得更好的性能。 - chris