f1505.cpp

来自「it is a usefull thing」· C++ 代码 · 共 20 行

CPP
20
字号
//=====================================
// f1505.cpp
// 申请内存出错
//=====================================
#include<iostream>
#include<exception>
using namespace std;
//-------------------------------------
int main(){
  try{
    int* p = new int[1000000000];  // 将导致异常
    p[1000000]=1000;
    cout<<p[1000000]<<"\n";
  }catch(bad_alloc){
    cout<<"Bad Allocation...\n";
  }
  cout<<"end of programm.\n";
}//====================================

 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?