#include //C++ example #include #include //for nothrow using namespace std; int main(int argc, char **argv) { cout << "How many int's do you want to allocate? "; size_t n; cin >> n; int *const p = new(nothrow) int [n]; if (p == 0) { cerr << argv[0] << ": can't allocate " << n << " int's\n"; return EXIT_FAILURE; } p[0] = 10; p[1] = 20; p[2] = 30; //etc. p[n - 1] = 40; //Warning: the subscripts only go up to n-1. delete[] p; return EXIT_SUCCESS; }