The role of 1.extern
Self-understanding: it should be necessary to differentiate the role of extern in C and C + + language, the C language of extern declaration of functions and variables can be referenced by the external module of the file, in addition to the role of the C + + language can also declare the extern "C" Declaration of a section of code to compile the connection method of C language method.
Reference: In fact, the extern Baidu entry explanation is very clear, concrete is also with me above own understanding difference is not very big.
(a) extern is a keyword that declares the scope (visibility) of functions and global variables in a C + + language, which tells the compiler that its declared functions and variables are used in this module or in other modules (typically, In the module's header file, the function and global variables that this module provides to other modules are declared with the keyword extern. )
(b) Variables and functions modified by extern "C" are compiled and linked in C language. (c language does not support function overloading, so the function of C + + and C are compiled differently, this sentence is to implement C + + and C and other languages mixed programming)
Functions of the 2.STRSTR () function
The Strstr () function is typically prototyped as an extern char * STRSTR (const char *SRC, const char *dest), which is intended to look for the position where the target string first appears in the source string.
3.windows Thread priority issues (differences and connections between processes and threads)
I think this concept may not be very suitable for interview, written Test, after all, platform-related, most companies may be more inclined to the development of Linux, the problem of replacement for the process and the thread of the difference is better, this is a written test, interview common knowledge to examine.
(a) Typically a process can contain several threads that can take advantage of the resources owned by the process. A process is an independent unit of system resource allocation and scheduling, a thread is an entity of a process, a basic unit of CPU dispatch and dispatch, and a smaller unit that can run independently than a process. The thread itself does not own the system resources, and only has some resources (such as program counters, a set of registers and stacks) that are essential in the run, and the thread can share all the resources owned by the process with other threads that belong to one process.
Thread and process differentiation: address space and other resources: processes are independent of each other, shared by threads of the same process. Communication: Inter-process communication IPC, between threads can read and write directly into the program data segments (such as global variables) to communicate-need to synchronize and mutually exclusive auxiliary. Scheduling and switching: Thread context switching is faster and more efficient than a process context switch. In a multithreaded OS, a process is not an executable entity.
4. Multi-method Exchange values for X and Y
5. Self-addition and reference of pointers
6. Pre + + and Post + +
Front + + and rear + + I think a more important question is how to distinguish between overloading two operators in C + +: A parameter that distinguishes between pre-and post-function parameters (function overloading), and an (int) parameter for post + +.
The role of 7.inline
The inline function does not operate as a normal function when called, and it embeds the program code directly into the calling code snippet, meaning that using the inline function increases the volume of the binary, but it makes the execution faster.
Also, parameters can be strongly typed during compilation, which is one aspect of inline over macros.
8. Representation of two-D arrays
The role of 9.ifndef
Conditional compilation syntax, in general, all rows in the source program are compiled. However, sometimes it is desirable to compile a part of the content only if certain conditions are met, that is, to specify the conditions for the compilation of some content, which is "conditional compilation". Sometimes, you want to compile a set of statements when a condition is met, and then compile another set of statements when the condition is not met.
10.KMP algorithm
Advanced algorithms for string matching
11. Function call method __cdecl stack is pressed into the stack by the caller purge parameters from right to left, the __stdcall stack is pressed into the stack by the callee purge parameters from right to left __fa The Stcall stack is saved in the register by the callee cleared part of the parameter, and then the other thiscall (non-keyword) stack is pressed into the stack by the callee purge parameter, and the this pointer is stored inside the ECX register
12. Overloaded functions
function overloading means that within the same scope, there can be a set of functions with the same function name and different parameter lists, which are called overloaded functions. You cannot overload with a return type. The function const and non-const in a class can be overloaded, but the principle is that the type of this pointer is overloaded with const and non-const, in fact the principle is that the parameter type is different, the const pointer orconst refers to the function called the const version of the functions ~ more overloaded knowledge of the function.
13. Constructors and destructors
The usage scenario for a virtual destructor is that a pointer to the parent class is actually a subclass pointer, and a virtual destructor is used when the delete is called to prevent partial memory leaks.
A constructor cannot be declared as a virtual function because the pointer to the virtual function table of an object is actually a code that is added by the compiler inside the constructor, so the virtual function table cannot be accessed until the constructor executes.
14. Merging two ordered linked lists
Like merge sort, two pointers can be merged.
1.51 billion recorded text files, remove the top 10 duplicates
Similar to the top K algorithm, the top K algorithm, which can not read all the memory, is the top K algorithm that achieves linear time by using the largest heap with a capacity of K.
First, the number of occurrences of each element is preprocessed using hash table, and then the top K algorithm is executed using the number of times.
16. Design a doubly linked list and provide a function that can delete elements based on values
The list bottom of the STL and is implemented for the doubly linked list.
17. Implementation of multiple traversal algorithms for two-fork tree
18. Have read and write two threads and a queue, the read thread reads the data from the queue, the write thread writes the data to the queue
Producer and Consumer models:
Use semaphore and mutex. semaphore mutex = 1;
Semaphore fillcount = 0;
Semaphore emptycount = buffer_size;
Procedure producer () {
while (true) {
item = Produceitem ();
Down (Emptycount);
Down (mutex);
Putitemintobuffer (item);
Up (mutex);
Up (Fillcount);
}
}
Procedure consumer () {
while (true) {
Down (Fillcount);
Down (mutex);
item = Removeitemfrombuffer ();
Up (mutex);
Up (Emptycount);
Consumeitem (item);
}
Copy the Code
The
does not use semaphore and mutex. volatile unsigned int producecount, consumecount;
Tokentype Buffer[buffer_size];
void producer (void) {
while (1) {
while (Producecount-consumecount = = buffer_size)
sched_yield ();//buffer full
buffer[producecount% buffer_size] = Producetoken ();
producecount + = 1;
}
}
void consumer (void) {
while (1) {
while (Producecount-consumecount = = 0)
sched_yield ();//Buffer Empty
consumetoken (buffer[consumecount% buffer_size]);
consumecount + = 1;
}
} Copy Code
19.stack,heap,memory-pool
20.TCP flow control and congestion control mechanism
TCP traffic control is to let the sender of the sending rate is not too fast, so that the receiving party in time to receive. The sliding window mechanism can be used to control the sender's traffic conveniently on the TCP connection. The window unit of TCP is a byte, not a message segment, and the sender's sending window cannot exceed the value of the receiving window given by the receiving party.
The so-called congestion control prevents excessive data from being injected into the network, which can prevent routers or links in the network from overloading. Congestion control asks for a premise that the network can withstand the existing network load. Flow control is often directed to point traffic control, is an end-to-end problem. The Internet recommended standard RFC2581 defines four algorithms for congestion control, namely slow start (Slow-start), congestion avoidance (congestion avoidance) Fast retransmission (fast restrangsmit), and fast reply (Fast Recovery).