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. Required fields are marked *

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

All trademarks and copyrights on this page are owned by their respective owners. Quotes from linked articles are probably the property of the publications linked or the property of the person(s) quoted. The rest © 2001- 2024 by James A. Chappell