Want to be an embedded programmer should know 0x10 basic questions

  

C language testing is a necessary and effective way to recruit embedded system programmers. Over the years, I have participated in and organized many of these tests. In the process, I realized that these tests can provide a lot of useful information for the interviewer and the interviewee. In addition, the pressure to open the interview is not discussed. Quite interesting. From the perspective of the interviewee, you can learn a lot about the issuer or the proctor. Is this test designed by the subject to show his knowledge of the details of the ANSI standard rather than technical skills? Is this stupid question? If you want to answer the ASCII value of a character. Do these issues focus on your system call and memory allocation strategies? This indicates that the author may spend time on the microcomputer instead of on the embedded system. If the answer to any of the above questions is "is" then I know I have to seriously consider whether I should do the job. From the interviewer's point of view, a test may reveal the quality of the candidate in many ways: Basically, you can understand the level of the candidate's C language. Anyway, it’s interesting to see how this person answers questions he won’t. Is the candidate making a wise choice with good intuition, or is it just a sin? When the candidate is stuck on a problem, is it an excuse, or does it show real curiosity about the problem, seeing it as a learning opportunity? I found this information to be as useful as their test scores. With these ideas in mind, I decided to come up with some exam questions that really target the embedded system. I hope that these headache questions will help those who are looking for a job. These problems are actually encountered by me over the years. Some of these questions are difficult, but they should all give you some inspiration. This test is suitable for different levels of candidates. Most of the primary level candidates will have poor grades, and experienced programmers should have good grades. In order for you to decide your own preferences for certain questions, there is no score assigned to each question. If you choose these questions for your use, please assign your own scores according to your wishes. Preprocessor

1. Declare a constant with the preprocessor directive #define to indicate how many seconds in a year (ignoring the leap year problem)

#define SECONDS_PER_YEAR (60 * 60 * 24 * 365) UL I want to see a few things here: 1; #define Basic knowledge of grammar (for example: can not end with a semicolon, use of parentheses, etc.)

2; The preprocessor will calculate the value of the constant expression for you, so it's clearer and no cost to write directly how you calculate how many seconds in a year instead of calculating the actual value. 3; Realize that this expression will overflow an integer of a 16-bit machine - so use the long integer L to tell the compiler that the constant is a long integer. 4; If you use UL (indicating unsigned long integers) in your expression, then you have a good starting point. Remember, the first impression is important. 2. Write a "standard" macro MIN that takes two arguments and returns the smaller one.

#define MIN(A,B) ((A) <= (B) ? (A) : (B))

This test is for the following purposes: 1; Identify the basics of #define application in macros. This is important because macros are the only way to easily generate embedded code until the inline operator becomes part of standard C. For embedded systems, embedding code is often necessary to achieve the required performance. Methods. 2; knowledge of the triple condition operator. The reason this operator exists in C is that it allows the compiler to produce code that is more optimized than if-then-else. It is important to understand this usage. 3; know how to carefully enclose parameters in parentheses in the macro 4; I also use this question to start discussing the side effects of macros, for example: What happens when you write the following code?

least = MIN(*p++, b);

3. What is the purpose of the preprocessor identifier #error? If you don't know the answer, see Reference 1. This question is useful for distinguishing between a normal buddy and a nerd. Only nerds can read the appendix of the C language textbook to find answers to such questions. Of course, if you are not looking for a nerd, then candidates should hope that they do not know the answer. Infinite loops

4. Infinite loops are often used in embedded systems. How do you write infinite loops in C? This problem uses several solutions. My preferred solution is:

while(1){}


Some programmers prefer the following:

for(;;){ }


This implementation makes me embarrassed because this grammar does not exactly express what is going on. If a candidate gives this as a solution, I will use this as an opportunity to explore the basic principles of doing so. If their basic answer is: "I was taught to do so, but never thought about why. "This will leave a bad impression on me. The third option is to use goto

Loop:...goto Loop;

The candidate gives the above solution, which means that he is an assembly language programmer (this may be Good thing) or he is a BASIC/FORTRAN programmer who wants to enter new fields.

Data declarations

5. Use the variable a to give the following definitions a) an integer (An integer) b) a pointer to an integer (A pointer To an integer) c) A pointer to a pointer pointing to an integer (A pointer to a pointer to an intege) rd) An array of 10 integers ( An array of 10 integers e) An array of 10 pointers pointing to an integer. (An array of 10 pointers to integers) f) A pointer to an array of 10 integers (A pointer to an array of 10 integers) g) A pointer to a function that has an integer argument and returns a A pointer to a function that takes an integer as an argument and returns an integer h) an array of 10 pointers to a function that has an integer argument and returns an integer ( An array of ten pointers to functions that take an integer argument and return an integer )

The answer is: a) int a; //An integer b) int *a; //A pointer to an integer c Int **a; //A pointer to a pointer to an integer d) int a[10]; //An array of 10 integers e) int *a[10]; //An array of 10 pointers to integers f Int (*a)[10]; //A pointer to an array of 10 integers g) int (*a)(int); //A pointer to a function a that takes an integer argument and returns an integer h) Int (*a[10])(int); //An array of 10 pointers to functions that take an integer argum Ent and return an integer People often claim that there are several questions that are the kind of questions that can be answered by flipping through the book. I agree with this statement. When I was writing this article, in order to determine the correctness of the grammar, I did check the book. But when I was interviewed, I expected to be asked this question (or a similar question). Because during the interview, I am sure I know the answer to this question. If the candidate does not know all the answers (or at least most of the answers), then there is no preparation for this interview. If the interviewer is not prepared for the interview, why can he prepare?

Copyright © Windows knowledge All Rights Reserved