Skip to content

Instantly share code, notes, and snippets.

@Morse-Code
Created April 4, 2013 12:36
Show Gist options
  • Save Morse-Code/5310016 to your computer and use it in GitHub Desktop.
Save Morse-Code/5310016 to your computer and use it in GitHub Desktop.
Reverse a C string using bitwise XOR operator.
void stringReverse(char *str)
{
char *p1, *p2;
if (!str || !*str)
{
NSLog(@"No string passed into reverse function.");
}
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
{
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
}
@akashdecoder
Copy link

can u please give me the explanation of line 11 12 13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment