1. use the preprocessing command # define to declare a constant to indicate the number of seconds in a year (ignore the leap year problem) # define SECONDS_PER_YEAR (60*60*24*365) ul I want to see a few things here: 1 ). # basic knowledge of define syntax (for example, it cannot end with a semicolon or use of parentheses) 2 ). knowing that the pre-processor will calculate the value of a constant expression for you, therefore, it is clearer and easy to directly write how much seconds you calculate in a year rather than calculate the actual value. 3) realize that this expression will overflow the integer number of a 16-bit machine-so the long integer sign L is used to tell the compiler that this constant is the long integer number. 4). If you use UL in your expression to represent an unsigned long integer, you have a good starting point. Remember, the first impression is very important. 2. Write A "standard" macro MIN. This macro inputs two parameters and returns A smaller one # define MIN (A, B) (A) <= (B )? (A) :( B) This test is intended for the following purposes: 1). LOGO # basic knowledge of define application in macros. This is important, because until the inline operator becomes part of standard C, macros are the only way to facilitate the generation of embedded code. For embedded systems, in order to achieve the required performance, embedded code is often a required method. 2) knowledge of triple-condition operators. The reason for the existence of this operator in C language is that it enables the compiler to produce code that is more optimized than if-then-else. It is important to understand this usage. 3 ). understand how to carefully enclose parameters in macro brackets. 4 ). I also use this question to discuss the side effects of macros. For example, what happens when you write the code below? Least = MIN (* p ++, B); 3. Infinite loops are often used in embedded systems. How do you write an infinite loop in C? There are several solutions to this problem. My preferred solution is: while (true) {} Some programmers prefer the following solution:, because this syntax does not exactly express what is going on. If a candidate provides this solution, I will use this as an opportunity to explore the basic principles of their practice. If their basic answer is: "I was taught to do this, but I never thought of why ." This leaves a bad impression on me. The third solution is to use goto Loop:... goto Loop; 4. What is the role of the keyword static? Few people can answer this simple question completely. In C language, the keyword static has three obvious functions: 1). In the function body, a variable declared as static maintains its value unchanged during the function call process. 2) within a module (but in the external body of the function), a variable declared as static can be accessed by the function used in the module, but not by other functions outside the module. It is a local global variable. 3) in a module, a function declared as static can only be called by other functions in the module. That is, this function is restricted to use within the local scope of the module that declares it. Most of the respondents can answer part 1 correctly. Some of them can answer part 2 correctly. Few people can understand part 3. This is a serious disadvantage of a candidate because he obviously does not understand the benefits and importance of localized data and code scope. 5. What is the meaning of the keyword const? Const means "read-only" const int a; a is a constant integer int const a; a is a constant integer const int *; a is a pointer to the constant integer number int * const a; a is a constant pointer to the integer number int const * a const; a is a constant pointer to a constant integer. 6. what is the meaning of the keyword volatile and three different examples are given? A variable defined as volatile means that this variable may be unexpectedly changed, so that the compiler will not assume the value of this variable. Precisely, the optimizer must carefully re-read the value of this variable every time when using this variable, rather than using the backup stored in the register. The following are examples of volatile variables: Ø hardware registers of parallel devices (such as status registers) Ø Non-automatic variables (Non-automatic variables) that will be accessed in an interrupt service subroutine) Ø variables shared by several tasks in multi-threaded applications 7. in which situations can B be implicitly converted to A for non-C ++ built-in types A and B? [C ++ medium] a. class B: public {......} // The Public B inherits from A, which can be indirectly inherited B. class B {operator A () ;}// B implements implicit conversion to A. c. class A {A (const B &) ;}// A constructor d. A & operator = (const A &); // value assignment operation. Although it is not an authentic implicit type conversion operation, it can barely calculate 8. which class member functions are generated by default for empty classes in C ++? Class Empty {public: Empty (); // default constructor Empty (const Empty &); // copy constructor ~ Empty (); // destructor Empty & operator = (const Empty &); // value assignment operator Empty * operator &(); // address retrieval operator const Empty * operator & () const; // address retrieval operator const}; 9. is a parent class written with a virtual function? Can a sub-class overwrite its functions without the virtual function realize polymorphism? Virtual modifiers are implicitly inherited. Private is also integrated, but the derived class has no access permission. Virtual instances can be added or not added. All variables of the parent class (except static) exist in the space of the Child class ). Only one entity exists in a function (except inline ). The sub-class can also implement polymorphism without adding virtual to its function. In the subclass space, there are private variables of the parent class. Private variables cannot be accessed directly. 10. without a third-party parameter, exchange the values of the two parameters a = a + B-(B = a) // use addition or subtraction, and the value does not overflow 11. which of the following methods can be used for inter-process communication? Inter-process communication methods include shared memory, pipeline, Socket, message queue, and DDE. 12. Given the following sqldatabase: Test (num INT (4), use an SQL statement to return the minimum value of num, but do not use statistical functions, such as MIN and MAX. Select top 1 num from Test order bynum desc13. differences between CriticalSection and Mutex brief summary object names of several synchronization objects speed cross-process description fast Critical Section speed cannot be used for different processes cannot perform resource statistics (only one thread can access Shared resources at a time) slow Mutex speed can be used for different processes. Resource statistics are not allowed for different processes. Slow Semaphore speed can be used for resource statistics for different processes www.2cto.com (one or more threads can access Shared resources) slow Event speed can be used by different processes for resource statistics 14. what are the characteristics of static variables and static functions? Static variable: it remains valid during the running period. If it is defined outside the function, it is visible within the compilation unit. If it is within the function, it is visible within the defined block. Static function: visible in the compilation unit.