Thursday, May 22, 2008

Adobe Interview - C Function to Reverse a String

Question: Write a C Function to Reverse a String

Note: This question was supposedly asked sometime back in the 'C Programming' section of the written test for a Dev position at Adobe. The question is purely based on memory and collected either from friends, colleagues, or Web. No guarantee whether the same question actually appeared in their test. However, you may use it to your advantage by having a feel of the type of questions Adobe asks.

Solution: Fairly easy one, I guess. The steps are as follows:

  • Compute the length and store in a variable
  • Declare one temporary variable to iterate through the string
  • Iterate through the string array (only half length) from both the ends
  • Keep swapping the characters during the iteration
  • Exit from the loop. The string is reversed now :-)

Find above the Code Snippet in C (as it was supposedly asked in the C Programming section :-)). Click the image to enlarge it.


No comments: