Embedded interview question 2

Source: Internet
Author: User
Tags integer numbers
1. use the command # define to declare a constant to indicate how many seconds are used in a year (ignore the leap year problem) Answer: # define second_per_year (60*60*24*365) ul2. write a standard macro min. This macro inputs two parameters and returns a smaller one: # define min (A, B) (a)> (B )? (A): (B) 3. an infinite loop that is often used in embedded systems. Use C to write an infinite loop while (1) {} 4. data Declaration: use variable A to give the following definition. 1) an integer number int A; 2) a pointer to an integer number int * A; 3) a pointer to a pointer, it points to an integer int ** A; 4) an array with 10 integer numbers int A [10]; 5) An array with 10 pointers, this pointer points to an integer int * A [10]; 6) a pointer to a 10 integer array int (* A) [10]; 7) A pointer to a function. This function has an integer parameter and returns an integer int (* A) (INT); 8) An array with 10 pointers, this pointer points to a function that has an integer parameter and returns an integer int (* A [10]) (INT); 5. keyword static: 1) in the function body, a variable declared as static maintains its value unchanged during the function call process. Int fun () {static int A = 5; // accumulate a ++; return a;} 2) in the module (but in the function body) A variable declared as static can be accessed by all functions in the module, but not by other functions outside the module. 3) in a module, a function declared as static can only be called by other functions in the module. 6. what does the keyword const mean? A: const can protect Variable Parameter const int A that does not want to be changed; A is a constant INTEGER (remove the type to protect the nearest one) const int * A; (* A cannot be modified, and a can be modified) A is a pointer to the constant integer int * const A; (a cannot be modified, * A can be modified) A is a constant pointer to the integer int const * a const; (* neither a nor a can be modified) A is a constant pointer to the constant integer 7. what is the meaning of the keyword volatile? Three Different examples are provided. A: The optimizer will re-read the value of the variable when processing the variable modified by volatile, instead of using backups stored in registers (which may be unexpectedly changed) 1) Hardware registers of parallel devices (Status Registers) 2) non-automatic variables accessed in an interrupt service subroutine 3) variables shared by several tasks in a multi-threaded application 8. A parameter can be cons. T, can it be volatile? A: Yes, read-only Status Register. It is volatile because it may be unexpectedly changed. It is const because the program should not try to modify it 9. int square (volatile int * PTR) {return * PTR ** PTR;} function error A: * The PTR value may be unexpectedly changed, the returned value is not the expected square value. Change: Long square (volatile int * PTR) {int A; A = * PTR; return a * A;} 10. bitwise operations give an integer variable A and write two pieces of code. The first one sets bit 3 of A and the second one clears bit 3 of A. In the preceding two operations, the other bits must remain unchanged. Answer: # define bit3 (0x1 <3) Static int A; void set_bit3 (void) {A | = bit3;} void clear_bit3 (void) {A & = ~ Bit3;} 11. embedded Systems that access fixed memory locations often require programmers to access points in specific memory locations. The value of an integer variable whose absolute address is 0x6780 must be set to 0x5566. A: int * P; P = (int *) 0x6780; * p = 0x5566; (it is valid to forcibly convert an integer into a pointer when accessing an absolute address) 12. interrupt Service Program ISR (Please comment) _ interrupt double compute_area (doble radius) {double area = pI * radius; printf ("\ n area = % F ", area); return area;} answer: 1) ISR cannot return values. 2) ISR cannot pass parameters. 3) Some compilers cannot perform floating-point operations in ISR. 4) printf has the re-entry problem 13. what is the output of the following code? Why? Void Foo (void) {unsigned int A = 6; int B =-20; (a + B> 6 )? Puts ("> 6"): puts ("<= 6");} answer: output> 6, because the expression contains symbols and unsigned types, all operands are automatically converted to unsigned 14. evaluate the following code: Unsigned int zero = 0; unsigned int compzero = 0 xFFFF; A: Incorrect unsigned int compzero = ~ 0;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.