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 XOR technique 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 two chars.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With