C++ interview questions

1. What are the internal implementations of STL and data structures (note efficiency and complexity) vector and list? What application scenarios are they applicable to? What is the time complexity of random access to vector? How to optimize the lookup speed of a vector? How does Vector expand? How do I completely empty a vector? How does a vector find elements? How do I find the specified element in a vector if it is a structure? (find find_if) Complexity of map lookup? How is map implemented at the bottom? What is the difference between map and HashMap? When should you use a Map and when should you use a HashMap? Common sorting algorithms and their time and space complexity? Do you know anything about bucket sorting? Given a scenario, choose an appropriate container? How do I define a ring queue? How to determine whether a ring queue is empty or full?

2. The difference between references and Pointers in C++?

Object reference is an alias, reference is the object operation, operation must be initialized at the same time of creating effective (refer to a valid object, not NULL), did not change the initialization, referenced with the efficiency of the pointer, variables and ease of use and intuitive, in the use of the language level and the reference object, At the binary level references are usually done through Pointers, but the compiler does the conversion for us. References are used to do the right thing with the right tools, embodying the principle of least privilege.

3. Extern “C” is used when calling a function in a C++ program that has been compiled by the C compiler.

Extern is a C/C++ keyword that indicates the scope (visibility) of functions and global variables that can be declared in this module or other modules. Normally, functions and global variables that this module provides references to other modules are declared with the extern keyword in a module’s header file.

4. Brief the differences between StrCPy, Sprintf and memCPy

The three main differences are as follows:

(1) Different operation objects, strcpy two operation objects are strings, sprintf operation source object can be a variety of data types,

The target operation object is a string, and the two objects of memcpy are two arbitrary memory addresses that can be manipulated, regardless of the data type. (2) Different execution efficiency, memCPY is the highest, strCPY is the second, sprintF is the lowest efficiency.

(3) implementation function is different, strCPy mainly realizes the copy between string variables, sprintF mainly realizes the conversion of other data type format to character string, memCPy is mainly the copy between memory blocks.

Strcpy, sprintf and memcpy can realize the function of copy, but for the object is different, according to the actual needs, to choose the appropriate function to realize the function of copy.