Trying to decide if your potential new embedded programmer hire has what it takes? Need a little help with embedded-specific interview questions? Or do you simply want to take a break and have fun with a test?
Electro-Tech-Online member known as amol. guilhane07 has compiled 16 questions to ask when recruiting embedded systems programmers. We list the questions here — but we aren’t giving you the answers right away. Try the test yourself and then follow the link at the end to Amol’s pdf with questions and answers. Let us know how you did and if you found the questions useful.
Tip: Click the code for a clearer image in a new window.
An obligatory and significant part of the recruitment process for embedded systems programmers seems to be the ‘C Test’. Over the years, I have had to both take and prepare such tests and in doing so have realized that these test can be very informative for both the interviewer and interviewee. Furthermore, when given outside the pressure of an interview situation, they can also be quite entertaining (hence, this article).
From the interviewer’s perspective, you can learn a lot about the person that has written or administered the test. Is the test designed to show off the writer’s knowledge of the minutiae of the ANSI standard rather than to test practical know-how? Does it test ludicrous knowledge, such as the ASCII values of certain characters? Are the questions heavily slanted towards your knowledge of system calls and memory allocation strategies indicating the writer may spend his time programming computers instead of embedded systems? If any of these are true, then I know I would seriously doubt whether I want the job in question.
From the interviewer’s perspective, a test can reveal several things about the candidate. Primarily, one can determine the level of the candidate’s knowledge of C. However, it is also very interesting to see how the personal reasons to choices, backed up with some good intuition, or do they just guess? Are they defensive when they are stumped or do they exhibit a real curiosity about the problem, and see it as an opportunity to learn something? I find this information as useful as their raw performance on the test.
With these ideas in mind, I have attempted to construct a test that is heavily slanted towards the requirements of embedded systems. This is a lousy test to give to someone seeking a job writing compilers! The questions are almost all drawn from situations I have encountered over the years. Some of them are very tough, however, they should all be informed.
This test may be given to a wide range of candidates. Most entry-level applicants will do poorly on this test, while seasoned veterans should do very well. Points are not assigned to each question, as this tends to arbitrarily weight certain questions. However, if you choose to adopt this test for your own use, feel free to assign test scores.
Q1: Using the #define statement, how would you declare a manifest contact that returns the number of seconds in a year? Disregard leap years in your answer.
Q2: Write the “standard” MIN macro. That is, a macro that takes two arguments and returns the smaller of the two arguments
Q3: What is the purpose of the preprocessor directive #error?
Q4: Infinite loops often arise in embedded systems. How does one code an infinite loop in C?
Q5: Using the variable a, write down definitions of the following:
- An integer
- A pointer to an integer
- A pointer to a pointer to an integer
- An array of ten integers
- An array of ten pointers to integers
- A pointer to an array of ten integers
- A pointer to a function that takes an integer as an argument and returns an integer
- An array of ten pointers to functions that take an integer argument and return an integer
Q6: What are the uses of the keyword static?
Q7: What does the keyword “const” mean?
Q7.1: What do the following incomplete declarations mean?
const int a ;
int const a ;
const int *a ;
int * const a ;
int const * a const ;
Q8: What does the keyword volatile mean? Give three examples of its use.
(a) Can a parameter be both const and volatile? Explain your answer.
(b) Can a pointer be volatile? Explain your answer.
(c) What is wrong with the following function?:
Q9: Embedded systems always require the user to manipulate bit sin registers or variables. Given an integer variable a, write two code fragments. The first should set bit 3 of a. The second should clear bit 3 of a. In both cases, the remaining bits should be unmodified.
Accessing Fixed Memory Locations
Q10: Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project, it is required to set an integer variable at the absolute address 0x67x9 to the value 0xaa55. The compiler is a purse ANSI compiler. Write code to accomplish this task.
Q11: Interrupts are an important part of embedded systems. Consequently, many compiler vendors offer an extension to standard C to support interrupts. Typically, this new keyword is interrupt. The following code uses interrupt to define an interrupt service routine. Comment on the code:
Q12: What does the following code output and why?
Q13: Comment on the following code fragment:
Dynamic Memory Allocation
Q14: Although not as common as in a non-embedded computer, embedded systems still do dynamically allocate memory from the heap. What are the problems with dynamic memory allocation in embedded systems?
Q15: Typedef is frequently used in C to declare synonyms for pre-existing data types. It is also possible to use the preprocessor to do something similar. For instance, consider the following code fragment
The intent in both cases is to define dPS and tPS to be pointers to structure s. Which method (if any) is preferred and why?
A16: C allows some appalling constructs. Is this construct legal, and if so what does this code do?
You’re done! Download the original pdf here with the questions and answers.
Do you have questions of your own that you either you used in recruiting — or that were used on you? Share in the comments below and we’ll put them together in another future post.
- In Praise of the #error directive. ESP September 1999.
- Efficient C Code for Eight-Bit MCUs, ESP November 1988.