Stig Brautaset stig at
Thu May 10 22:50:54 BST 2007

>> something harder almost without the candidate noticing
> do you mean, asking for no temp variable and using the xor trick?  
> to be
> perfectly honest ive never liked that question as its too clever  
> for its
> own good imho. but maybe i just like simple code much like my  
> brane ;-),

No, I was not intending the xor-trick. I don't like those types of  
questions. Rather, I'd try to see if they understood pointers enough  
to get rid of the index variables. Something like the following:

#include <stdio.h>
#include <string.h>

int main(void)
     char s[] = "hello world";

     char *h = s;
     char *t = strchr(s, '\0');
     while (h < t) {
         char c = *h;
         *h++ = *--t;
         *t = c;


     return 0;


More information about the mailing list