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:
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.