could someone explain me what XOR,(^) does in the fallowing code exaclly and how come the function is a pointer?
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;
}
The function is not a pointer, but returns a
char*.The function reverses a string.
This
XORtechnique is used to swap two elements without any extra memory. As you can see, the loop iterates through the string’s start and end, and swaps the twochars.