1. Differences between malloc, free, new, and delete
First, malloc and free belong to a group of library functions in C. New Delete belongs to a group of operators in C ++. All functions are used to open up and release memory space. But the difference is. The new and delete operators call the class constructor and destructor when opening up the space. Malloc free does not have this function. (C does not have the concept of class either)
2. Which class member functions are generated by C ++ empty classes by default?
The compiler automatically generates four functions: default constructor, destructor, copy constructor, and assign value function.
3. The destructor in C ++ can be inline functions.
4. Differences between Delete and delete [] in C ++.
1. for basic types (INT, Char, float, etc.), the memory space opened up can be released using both operators.
Char * A = new char [300];
Delete A; // or delete [];
2. For the custom class type, after opening up the memory space of the class array, use Delete [] to release the memory. If delete is used, the memory can also be released, but it does not call the class
Destructor, resulting in incomplete release operations in the class.
Class T;
T* T = new T [20];
Delete t; // only the destructor of T [0] is called. Other objects are released without calling the destructor.
Delete [] T; // release the memory and call the corresponding destructor.