Sample Technical Questions

The function in Example 1 has several minor twists that can throw off inexperienced candidates: the exact meaning of const in this context, the use of the ternary operator, the use of pointer arithmetic, and the meaning of the return value from line 9. But the most interesting twist is in the for loop test on line 4. After line 3, where the variable c is set to the longest string length, the loop test adds that length to the first string parameter (whether or not the first string is the longest). This is deliberately strange. How candidates react to this as they analyze the function can be very telling. Do they immediately jump to the conclusion that it is a bug? (In fact, it is not.) Do they gloss over it without realizing something strange is going on? Or do they coolly withhold judgment? ("That looks like it may be a problem, but let me figure out the rest and I'll come back to it.") Eventually, most candidates realize that this is a twisted recoding of a Standard C Library function. After that, I ask candidates what "improvements" they would make to this function. The answers to that question are the most telling of all. I have heard a huge variety, from "change the variable names," to "recode the pointer notation as array notation," to "optimize out all the calls to strlen." (Which of these answers is "better" is left as the most important exercise for the reader.)

-- J.K.

Back to Article