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 );

```
This seems to work fine

```
void reverse(char *s, int len) { \
  if(len <= 1) \
    return; \
  char t; \
  char *e = s + len - 1; \
  while(s < e) { \
    t = *s; \
    *s = *e; \
    *e = t; \ 
    e--; \
    s++; \
  } \
}

```

Note that his code is all in one line. Prefer code clarity. If you can put a function's code into one line using language features, then use those features.