|
ex2-5.cpp - Example 2-5 Dynamic Memory Allocation - ints |
// File: ex2-5.cpp
#include <iostream>
#include <cstdlib>
#include <new>
using namespace std;
int main(void)
{
int i;
int* pint;
try {
pint = new int[99999];
cout << "memory is cheap\n";
}
// if the dynamic memory allocation fails, new throws a bad_alloc
catch (bad_alloc& uhoh) {
cerr << uhoh.what() << endl; // what() displays "bad allocation"
}
for (i = 0; i < 99999; i++) pint[i] = 0;
delete [] pint;
pint = 0;
return 0;
}
CIS27: Programming in C++ Instructor: Joe Bentley