Skip to content

Instantly share code, notes, and snippets.

@linusthe3rd
Created February 7, 2013 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linusthe3rd/4727217 to your computer and use it in GitHub Desktop.
Save linusthe3rd/4727217 to your computer and use it in GitHub Desktop.
in-place String reversal
void strrev(char *p) {
char *q = p;
while(q && *q) ++q; //get last char of the string
for(--q; p < q; ++p, --q) {
*p = *p ^ *q, //xor p
*q = *p ^ *q, // xor np w/ q to store p's value in q
*p = *p ^ *q; //xor np w/ nq to get q's original value in p
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment