C ++ interview preparation [two]

table of Contents

void


The difference between gcc and g ++

gcc and g ++ are the GNU (organization) of a compiler.

  1. gcc and g ++ can be compiled c code c ++ code. But: the suffix .c, gcc it as a C program, and g ++ as a C ++ program; .cpp suffix, both of which would be seen as a C ++ program.
  2. Compile phase, g ++ will invoke gcc, for c ++ code and the two are equivalent, but because the library does not automatically join gcc command and C ++ programs use, it is usually done with g ++ link.
  3. It can be compiled with gcc / g ++, and links with g ++ or gcc -lstdc ++. Because gcc command can not automatically coupled and C ++ libraries used by the program (of course, the link can be selected manually, using the following command), it is usually accomplished using g ++ coupling. But in the compilation stage, g ++ will automatically call gcc, both equivalent .

gcc compiler four steps

cc C compiler source code has four steps:
pretreatment .i ----> Compiler .s ----> assembler .o ----> Links

Stack overflow causes and solutions

The most common cause of stack overflow is excessive depth or infinite recursion , where the function calls itself too many times, so that the required storage space for each variable and the information associated with the call is beyond the scope of the stack.

  1. Infinite recursion -> if possible recursive algorithm Recursive unknown number or a large number of times, their own management recursive (by maintaining its own dynamically allocated stack) or the recursive algorithm into an equivalent iterative algorithm
  2. Very deep recursion -> ensure that any recursive algorithm terminates after a known maximum depth
  3. Very large stack variables -> Do not allocate large variables on the stack

Several cases of C ++ memory leaks

  1. In the constructor and destructor of no matching call new and delete functions
  2. Clear not properly nested object pointer
  3. When the object is released without the use of an array of square brackets in the delete
  4. Pointer to the object array is not identical to the array of objects
  5. Missing copy constructor
  6. Missing assignment operator overloading
  7. Common myths about nonmodifying operator overloading
  8. The destructor is not defined as the base class virtual function
  9. Wild pointer appears

[1]. Stack overflow. https://en.wikipedia.org/wiki/Stack_overflow

Guess you like

Origin www.cnblogs.com/lvjincheng/p/11322981.html