During the hiring process, Fundamental Software Solutions has always passed small tests of skill to potential developer hires. We don't ask much - just spot some commonly made mistakes, or identify what will most likely happen with some sample code. Now, we haven't been been the only ones doing this - and for good reason. Programming skill is highly varied. Does it work? So far.
Now for some fun. We have stumbled across the results of one particular interviewee of a pretty major company looking for C++ programmers. The interviewee was asked to create a small, efficient program that would take the input from a user and make it lowercase, without using any pre-made library functions to do the 'lowercasing.' The text will be plain, old ascii english characters, so don't worry about UNICODE or anything like that.
Here is a modified result of what was written. (We modified it to protect the job seeker from being googled, but the code is essentially the same.)
-
char * MakeTextLower(char *ptr)
- {
- while (*ptr != '\0')
- {
- if (*ptr > 'A' && *ptr < 'Z')
- {
- *ptr -= 'A' - 'a';
- }
- *ptr++;
- }
- return ptr;
- }
There are at least two problems with this code that make it non-functional. Can you spot them?
[Edit: For extra credit, the function is also going to return the wrong thing. Can you tell us what will be returned?]