The new and delete operators are new operators in C ++. They provide dynamic storage allocation and release functions. It is equivalent to the C language functions malloc () and free (), but the performance is superior. Using new has the following advantages over using malloc:
(1) New automatically calculates the size of the type to be allocated without using the sizeof operator, which is easy to use and can avoid errors.
(2) It automatically returns the correct pointer type and does not require forced pointer type conversion.
(3) You can use new to initialize the allocated object.
Example:
(1), int * P;
P = new int [10]; // assign an integer array containing 10 Integers
Delete [] P; // Delete this array
(2) int * P;
P = new int (100); // dynamically allocates an integer and initializes Delete and delete []. The difference is that a delete is static and a delete is dynamic. This article references: