#include #include using namespace std; int main() { cout << "How many ints do you want to store? "; size_t n {0}; cin >> n; try { //p always remains pointing to the same place. int *const p {new int[n]}; //This q can read and write. for (int *q {p}; q < p + n; ++q) { cout << "Please input int number " << q - p << ": "; cin >> *q; } cout << "Here are the " << n << " ints that you input:\n"; //This q can read but not write. for (const int *q {p}; q < p + n; ++q) { cout << q-p << ": " << *q << "\n"; } delete[] p; } catch (bad_alloc e) { cerr << "Sorry, Linux has no room for " << n << " ints.\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; }