首页 > 系统相关 >new 在堆内存中开辟内存空间,delete 释放开辟的内存空间

new 在堆内存中开辟内存空间,delete 释放开辟的内存空间

时间:2022-11-15 23:33:29浏览次数:49  
标签:int 内存空间 内存 new 开辟 delete

int main(){
     
  int * p =  new int(10);
    
    cout << *p << endl;
    
    delete p;
    
    cout << *p << endl;
    
int * arr  = new int[10];
    
    for(int i=0; i< 10 ; i++){
        arr[i] = i +10;
    }
    
    for(int i=0; i< 10 ; i++){
        cout <<  arr[i] << endl;
    }
    delete [] arr;
    cout <<  arr[0] << endl;
    return 0;
}

  

标签:int,内存空间,内存,new,开辟,delete
From: https://www.cnblogs.com/itniwota/p/16894465.html

相关文章