Small circle of embedded software engineers face questions ape summary two (the answer)

Last small circle jerk ape has summed up a set of "embedded software engineer interview questions one", this updated, welcomed everyone to read, I suggest that you do not look to see when the first answer, their first to do something, and then finish the correct answer to it and see how to do their own, do not say too much chicken soup, the little ape circle take you to see a following questions.

1, char * s = "AAA"; printf ( "% s", s); s [0] = 'B'; printf ( "% s", s); What is wrong?

The answer: "AAA" is a string constant. s is a pointer to the string constants, so when s statement of a problem. cosnt char * s = "AAA"; then because it is constant, so is the s [0] of the assignment is not legal.

2, char * constp char const * p const char * p of the three What is the difference?

The answer: char * const p; // constant pointer, the value of p can not be modified

char const * p; // pointer constant, the constant value can not be changed to point const char * p; // and char const * p

char * const p is a char type pointer, the pointer is a constant, not allowed to modify, i.e., p = q similar statement is wrong;

char const * p and const char * p is the same type of char pointer to the character is regarded as a constant can not be modified, i.e., * p = q similar statement is wrong.

3, a 32-bit machine, the machine is a pointer to how many?

The answer: just look at how many pointer is the number of bits of the address bus on the line. After the machine is 80386 data bus 32. Therefore, the number of bits the pointer is the 4 bytes.

4. What is the problem I ask the following code:

int  main() { chara; char *str=&a; strcpy(str,"hello"); printf(str); return 0; }

The answer: not as str allocate memory space, the problem will occur in abnormal copy a string into a character variable pointer address. Although the output is correct, but because of the inherent cross-border conduct reading and writing program crash.

5, embedded systems often use the infinite loop, how you use C to write an infinite loop.

Answer: while (1) {}, or for (;;)

6, citing several process synchronization mechanism, and compare their advantages and disadvantages.

Answer: atomic semaphore mechanism spin locks the tube, rendezvous, distributed system

Way communication between 7 process

Answer: The shared storage system messaging system piping: a file system-based

8, a necessary condition for deadlock 4

Answer: exclusive, request remains inalienable, loop

9 ,. difference between arrays and linked lists

Answer: Array: data is sequentially stored, and even fixed-size table: random data can be stored, can dynamically change the size of

10, a known array Table, with a macro definition, the number of elements determined data

答案:#defineNTBL #define NTBL (sizeof(table)/sizeof(table[0]))

11, write the result of the program

int sum(int a)

auto int c = 0; 

static int b=3;

c+=1;

b+=2;

return(a+b+c);

}

void main()

int I;

int a=2;

for(I=0;I <5;I++)

printf("%d,", sum(a));

}

}

A: 8,10,12,14,16 The problem is relatively simple. Note b declared as static as long as the static global variables whose values ​​on the next call can retain the original assignment can be.

12, please write the following code outputting content #include <stdio.h> main () {int a, b, c, d; a = 10; b = a ++; c = ++ a; d = 10 * a ++; printf ( "b, c, d:% d,% d,% d", b, c, d); return 0;}

答案:10,12,120  a=10;  b=a++;//a=11 b=10  c=++a;//a=12 c=12  d=10*a++;//a=13 d=120

The second set of embedded software developers face questions on here, how about we do, feel-good friends, it should be a very solid foundation, and if you are looking for a job in the state, you can safely try; do feel not very smooth friends, do not be discouraged, the knowledge will not re-learn it, you can go to a small circle ape look, do not put a good grasp of it.


Guess you like

Origin www.cnblogs.com/xiaoyuanquan/p/11016488.html