#include using namespace std; int main() { // p is a pointer to a pointer to an int, // allocate memory for pointer to int int** p = new int*[10]; // now allocate an int for each element and intitialize to the value of i for (int i=0; i<10; i++) { p[i] = new int(i); } // print as though it's a 2D array, second dimension only has one element for (int i=0; i<10; i++) cout << p[i][0] << " "; cout << endl; // displays 0 1 2 3 4 5 6 7 8 9 // treat one subscript as a pointer, get to p[i] and dereference for (int i=0; i<10; i++) cout << *p[i] << " "; cout << endl; // displays 0 1 2 3 4 5 6 7 8 9 // use p[i] and dereference, increment the contents of the element for (int i=0; i<10; i++) (*p[i])++; // display again for (int i=0; i<10; i++) cout << *p[i] << " "; cout << endl; // displays 1 2 3 4 5 6 7 8 9 10 // print again using pointer arithmetic and pointers to pointers for (int i=0, **ptr=p; i<10; i++, ptr++) cout << **ptr << " "; cout << endl; // displays 1 2 3 4 5 6 7 8 9 10 return 0; }