Nigel Jones from Maryland says he uses the following questions to interview embedded systems C programmers.
  1. What is the purpose of the preprocessor directive #error?
  2. How do you code an infinite loop in C ?
  3. What are the uses of the keyword static?
  4. What does the following code output?
    void foo(void)
    {
    unsigned int a=6;
    int b=-20;
    (a+b >6) ? puts(">6") : puts("<=6");
    }

1. Either you know the answer to this, or you don't. This question is useful for differentiating between normal folks and the nerds. Only the nerds actually read the appendices of C textbooks to find out about such things. Of course, if you aren't looking for a nerd, the candidate better hope she does not know the answer.

2. My preferred solution is:
while(1)
{
}

Many programmers seem to prefer:
for(; ;)
{
}

This construct puzzles me because the syntax doesn't exactly spell out what's going on. Thus, if a candidate gives this as a solution, I'll use it as an opportunity to explore their rationale for doing so. If their answer is basically, "I was taught to do it this way and I haven't thought about it since," it tells me something (bad) about them.

A third solution is to use a goto:
Loop:
...
goto Loop;

Candidates who propose this are either assembly language programmers (which is probably good), or else they are closet BASIC/FORTRAN programmers looking to get into a new field.

3. This simple question is rarely answered completely. Static has three distinct uses in C:


Most candidates get the first part correct.A reasonable number get the second part correct, while a pitiful number understand the third answer. This is a serious weakness in a candidate, since he obviously doesn't understand the importance and benefits of localizing the scope of both data and code.

4. The question tests whether you understand the integer promotions rules in C - an area that I find is very poorly understood by many developers. Anyway, the answer is that this outputs ">6". The reason for this is that expressions involving signed and unsigned types have all operands promoted to unsigned types. Thus -20 becomes a very large positive integer and the expression evaluates to greater than 6.This is a very important point in embedded systems where unsigned data types should be used frequently. If you get this one wrong, you are perilously close to not getting the job.