An Interview Question

Here’s some code stolen from The Daily WTF:

ushort GetAsciiValue (uchar ch)
    ushort i;
    for (i=0; i<=255; i++)
        if(ch == i)
            return i;
    return 0;

It might be interesting to show this code to a candidate for a C/C++ position. Ask him/her if there is anything wrong with this code, and if so, how he/she would implement GetAsciiValue.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.