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;
}

  

posted on 2022-11-15 23:27  知了不了了之  阅读(19)  评论(0编辑  收藏  举报