Interview Question

Software Engineer Interview Palo Alto, CA

Reverse a string in-place using C.

Answer

Interview Answer

2 Answers

2

void
reverse(char *str)
{
   char *end = str + strlen(str) - 1;

   while (end > str)
   {
      char t = *str;
      *str = *end;
      *end = t;

      str++;
      end--;
   }
}

Anonymous on Apr 15, 2010
2

You rated the interview as "Very Difficult", and yet the questions you posted are trivially easy and very common, was that supposed to be some sort of joke? :(

Anonymous on Oct 22, 2010

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up