First trial of Chengdu Elf Cloud

    I recently participated in the written test and interview at Chengdu Elf Cloud. The position was a C++ engineer. Later, I reviewed the process myself. The preliminary test part is summarized as follows. I hope it can provide some reference for students who want to join the company and interview C++ engineers. This is also the blogger's first interview, so he hasn't prepared many things yet, and many of his answers are not good, so some of the questions seem very abrupt.
    In the future, I will also share the interview and written test experience of each company in this column. If you want to see it, you can follow the blogger!

Links to other content

    Elf Cloud written test part

Text begins

    The first is to introduce yourself. I personally feel that as much as possible, it is enough to talk about content related to job hunting and show your abilities.

    The following is the question and answer session (high energy ahead!!!):

Q: Explain the static keyword
A: static is used to control the storage method and visibility of variables. The static function is only visible to the file; the static global variable is only visible to the file; the static local variable is to change the lifetime of the local variable.

    More about the principle of static can be found in the detailed explanation of the static keyword in the blog

Q: A statically defined global variable (why you ask this question is because the answer above is that it is only visible in this file)
A: Indicates that this is a static global variable, making the variable only available in this source file.

Q: Explain the const keyword
A: Modified with const, it means that the data of the variable can only be accessed, but not modified, which means "read-only"

Q: There are several types of const modified pointers, what are they?
A: There are three types, const modifies pointers - constant pointers; const modifies constants - pointer constants; const modifies both pointers and constants.

Q: const-modified member variables and member functions
A: A const-modified member variable is equivalent to the variable being a constant, so you can only initialize the
const-modified member function on the list. In fact, what is modified is the this pointer hidden by the member function. Indicates that the member function cannot modify the member variables of the class, so const cannot modify the constructor, destructor and assignment operator overloader

Q: Explain what an inline function is.
A: In order to eliminate the time and space overhead of function calls, C++ provides a method to improve efficiency, which is to replace the function call with a function body at compile time, similar to macro expansion in C language. This kind of function that embeds the function body directly at the function call is called an inline function
Q: Follow-up question - what is the overhead of calling the function
A: I was answering the process of function calling to explain the time and space overhead, so HR asked me directly the next question

Q: Briefly describe the function calling process
A: push the current running address into the stack;
  push the parameters into the stack, if there are fewer parameters, they will be stored directly in the register;
  jump to the target function address;
  execute the function body;
  destroy Local variables and function parameters;
  pop up the caller's running address;
  jump back to the caller;

Q: How does the program jump back to the caller after calling it
? A: Function calls and returns are managed through the call stack. Whenever a function is called, the program will push all the context of the current function into the call stack, and then start execution. When the called function completes execution and is ready to return, the program will pop the context of the function from the call stack and return control to the caller. The bottom layer uses the program counter PC to store the
  current The address of the executed instruction. When the function is called, the value of the PC will be saved to the function context in the call stack. When the function returns, the value of the program counter will be restored from the function context in the call stack so that the program can continue to execute. The next instruction of the caller function

Q: Explain the SP pointer (why I ask this is because I recorded the PC pointer as the SP pointer and got confused, ahhhhhh, so embarrassing) A: The
SP pointer is the stack pointer, used for popping and popping the stack. Push operation

Q: The difference between malloc and new
A: malloc is a function, and new is a keyword; malloc will not call the constructor, but new will call the constructor; malloc dynamically allocates memory in the heap area, and new dynamically allocates memory in the free storage area ; new will strictly return the object type pointer, malloc returns a void pointer, which needs to be cast; new will throw a bac_alloc exception if it fails, and malloc will return null; new will automatically allocate the size according to the object type, and malloc needs to specify the size of the allocated space.

    There are specific differences. Please refer to the detailed description of the difference between new and malloc.

Q: If an address is allocated using malloc, what is the value on the address? What if it is new?
A: Before the space requested by the malloc function is used, the random value new is stored in the space. If you
do not add () after it, it will not be initialized. It is a random value. If () is added, its value will be 0.

Q: The difference between overloaded functions and virtual functions
A: Overloaded functions only require functions to have the same function name, and overloaded functions are different functions with the same name defined in the same scope; virtual functions not only require the same function name, Moreover, the signature and return type of the function are required to be the same, which means that the function prototype must be exactly the same, and the virtual function characteristics must be reflected in the class hierarchy of the base class and the derived class.
  Overloaded functions can be member functions or friend functions, virtual functions can only be non-static member functions.
  Constructors can be overloaded, but destructors cannot be overloaded; constructors cannot be defined as virtual functions, and destructors can be defined as virtual The call of function
  overloaded function is based on the difference in the sequence of passed parameters as the basis for calling different functions, while the virtual function calls different types of functions according to different areas of the object. Overloaded functions
  show polymorphism at compile time and are static binding. , virtual functions show polymorphism at runtime and are dynamic binding

Q: Let’s talk about the relationship between virtual functions and virtual function tables.
A: Polymorphism is realized by virtual functions, and virtual functions are mainly realized through virtual function tables. In this table, it is mainly the address table of the virtual function of a class. This table solves the problem of integrated coverage. In an instance with a virtual function, this table is allocated in the memory of this instance, so when we use When using a parent class pointer to operate a subclass, this virtual function table is like a map indicating the actual function that should be called.

Q: Let’s talk about the advantages and disadvantages of chain structure and sequential structure.
A: Sequential storage structure is a continuous storage unit, which stores the data elements of a linear table in sequence; chain storage structure is a set of arbitrary storage units, which stores the elements of a linear table.
Linear table search is very convenient, but insertion and deletion are more troublesome.
Chain structure insertion and deletion is very convenient, but search is more troublesome.

Q: How to make the linked structure easy to search
A: Maintain an additional index data structure, each index node points to an element in the linked list, so that you can quickly search in the index structure, and then find the specific element according to the pointer in the linked list

Q: How to communicate between processes
A: Message passing (pipe, FIFO, posix and message queue)
 Synchronization (mutex locks, condition variables, read-write locks, file and record locks, Posix and System V semaphores)
 Shared memory area (anonymous Shared memory area, known as Posix shared memory area, known as System V shared memory area)
 procedure call

Q: How to create a pipeline
A: Use the function CreatePipe() in Windows and pipe() in Unix/Linux

Q: Explain what a smart pointer is.
A: Smart pointers help manage dynamically allocated memory, help us automatically release new memory, and avoid memory leaks.

Q: Explain the three-way handshake and four-way handshake of the tcp protocol.
A: The three-way handshake of tcp is to establish a reliable connection. First, the client sends a request to the server, the client switches to the sending state, and the server is in the listening state. After the request, the server returns a confirmation, and the server changes to the receiving state. After receiving the confirmation, the client returns a confirmation to the server, indicating that it has received the information returned by the server. The client switches to the connected state, and the server formally establishes the connection after receiving the information.
  The four-way handshake of tcp is to ensure that the client and server disconnect requests and data transmission are completed: first, the client sends a disconnect request, the server sends a confirmation to the client after receiving it, and the client enters a semi-connection after receiving the confirmation. status, indicating that it can only receive but not send. After the server finishes transmitting the information, it sends a disconnect request to the client. The client returns a confirmation after receiving it. The server disconnects the request after receiving it. The client waits for 2 maximum message survival times before disconnecting.
  The reason why the server is not allowed to return a confirmation connection while transmitting information: TCP has a timeout retransmission mechanism, which takes a short time. Waiting for the server to complete the transmission, it is estimated that the client will retransmit many times.

Guess you like

Origin blog.csdn.net/qq_43419761/article/details/132782948