C ++ | new and delete operators

Summary:

  Dynamic allocation and release of dynamically allocated memory function malloc and free memory in C, C ++ using new and delete operators to perform the same operation, but still stored in C ++ malloc and free

application:  

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main(){
 5     int *i;
 6     i = new int;
 7     *i = 9;
 8     cout<<*i;
 9     delete i; 
10 }
. 1 #include <the iostream>
 2  the using  namespace STD;
 . 3  
. 4  int main () {
 . 5      // one-dimensional array 
. 6      int * I;
 . 7      I = new new  int [ 100 ];
 . 8      
. 9      Delete [] I;
 10  
. 11      // two dimensional array J [10] [10] 
12 is      int ** J;
 13 is      J = new new  int * [ 10 ];
 14      for ( int m = 0 ; m < 10; m++) 
15         j[m] = new int[10];
16         
17     delete[] j;
18 }

Using multi-dimensional arrays can be used to solve the vector: https://www.csdn.net/gather_27/MtzaUgzsNzctYmxvZwO0O0OO0O0O.html

Guess you like

Origin www.cnblogs.com/jj81/p/11113350.html