Question: During a recent interview one of my friends was asked a question to reverse a string using only a single line of code.
The string is already stored in a `char*` variable.

I tried using recursion, but it never reduced to a single line of code.

Could anyone help me with this?

Answer: 
If you really want it in C, and `strlen` is allowed, this will work:

```
for( char *p = str, *q = str + strlen(str) - 1; p < q; *p ^= *q, *q ^= *p, *p++ ^= *q-- );

```

I do not recommend you to use this in any actual program... Anyone got an idea how to get rid of the `strlen`?

Edit: *even more beautiful*:

```
for( char *p = str, *q = strchr(str, 0) - 1, t; p < q; t = *p, *p++ = *q, *q++ = t );

```
It requires an ugly construct involving a while loop with character pointer arithmetic and both post-increment and post-decrement operators. Never, ever use such hideous code except in obfuscation contests. (No, not even in interviews. If they ask you such useless trivia, chances are they are equally clueless about other things.)