In the previous article, we introduced some common methods of C ++ two-dimensional array new in detail. I believe you should have some knowledge. In this article, we can compare the functions of C ++ delete and have a full understanding of this knowledge.
- Analysis of Different Methods of C ++ Memory Management
- C ++ iterator
- Detailed description of C ++ shallow copy
- Interpretation of the C ++ callback function code example
- Comments on several application methods of C ++ two-dimensional array new
New and C ++ delete operators are operators used to dynamically allocate and revoke memory
New usage:
1. Open a single variable address space
1) new int; // open up a bucket for storing arrays and return an address pointing to the bucket. int * a = new int: assign an int type address to integer pointer.
2) int * a = new int (5) serves the same purpose as above, but at the same time, the integer is assigned to 5
2. Open up array space
One-dimensional: int * a = new int [100]; opens up an integer array space of 100
Two-dimensional: int ** a = new int [5] [6]
3D and above: so on.
General Usage: new Type [initial value]
C ++ delete usage:
1. int * a = new int;
Delete a; // release the space of a single int
2. int * a = new int [5];
Delete [] a; // release the int array space
To access the struct space opened by new, the variable name cannot be used directly, but can only be accessed through the pointer of the value assignment.
New and C ++ delete can be used to dynamically open up and cancel the address space. when programming, if you use a variable (usually an array temporarily stored), you need to use it again next time, but want to save the effort of re-initialization, you can open up a space each time you start using it and undo it after it is used up.