// // new.cpp -- shows how to use the "new" operator to allocate new variables // The "new" operator allocates new space and returns a pointer // to that space. The space is reserved until it is "delete"-ed // #include using namespace std; int main() { int *p, *q; // define vars to hold the addrs int **z; // this one points to a ptr p = new int; // create the new space q = new int; // and store the addrs of those vars z = &p; // store the address of a ptr *p = 3; // use the ptrs to update the vars *q = 4; // use the ptrs to update the vars cout << **z << endl; // use the ptr to ptr to get vals delete p; // return the variables so they delete q; // can be used for something else return 0; }