3 common embedded C language interview questions with answers, come and learn!

Question 1:

Briefly describe the difference between strcpy sprintf and mencpy

After thinking about it, look for the answer below

Question 2:

How to avoid "wild pointers"

After thinking about it, look for the answer below

Question three:

Briefly describe the difference between pointer constants and constant pointers

After thinking about it, look for the answer below

3 common embedded C language interview questions with answers, come and learn!

Answer to question one:

The three main differences are as follows: (1) The operation objects are different. The two operation objects of strcpy are both strings. The operation source object of sprintf can be multiple data types. The target operation object is a string and two memcpy. Objects are two arbitrary operable memory addresses, not limited to any data type. (2) The execution efficiency is different, memcpy is the highest, strcpy is the second, and sprintf is the lowest. (3) The realization function is different, strcpy mainly realizes the copy between string variables, sprintf mainly realizes the conversion of other data type formats to strings, and memcpy is mainly the copy between memory blocks. Note: strcpy, sprintf and memcpy can all realize the copy function, but the target is different, according to the actual needs, choose the appropriate function to realize the copy function.

Answer to Question 2:

The causes and solutions of "wild pointer" are as follows: (1) The pointer variable is not initialized when it is declared. Solution: The pointer is initialized when it is declared, it can be a specific address value, or it can point to NULL. (2) After the pointer p is free or deleted, it is not set to NULL. Solution: The pointer should point to NULL after the memory space pointed to by the pointer is released. (3) The pointer operation goes beyond the scope of the variable. Solution: Release the address space of the variable before the end of the scope of the variable and let the pointer point to NULL. Note: The "wild pointer" solution is also the basic principle of the programming specification. We must avoid generating "wild pointer" when using pointers, and we must check the legitimacy of pointers before using them.

Answer to question three:

Pointer constant refers to the definition of a pointer, the value of this pointer can only be initialized when it is defined, and cannot be changed elsewhere. In fact, the pointer constant is unique, that is, NULL; the constant pointer refers to the definition of a pointer, this pointer points to a read-only object, and the value of this object cannot be changed through the constant pointer. The pointer constant emphasizes the immutability of the pointer, while the constant pointer emphasizes the immutability of the pointer to the object it refers to. Note: Regardless of whether it is a pointer constant or a constant pointer, its greatest use is to serve as a formal parameter of a function to ensure the immutability of the actual parameter in the called function.


VapeSoul Vape

Vapesoul Vape,Disposable Vape Review,Hqd Maxx Hqd Cuvie Plus,12 Fruit Flavors Disposable Vaporizer

TSVAPE Wholesale/OEM/ODM , https://www.tsecigarette.com

This entry was posted in on