//--- Demonstration of dereferencing pointers // -- augmented version of example Fig2-5.cpp from Nyhoff, // "ADTs, Data Structures and Problem Solving with C++" #include using namespace std; int main() { int i = 11, j = 22; double d = 3.3, e = 4.4; // Declare pointer variables that: int * iPtr, // store addresses of ints * jPtr; double * dPtr, // store addresses of doubles * ePtr; iPtr = &i; // value of iPtr is address of i jPtr = &j; // value of jPtr is address of j dPtr = &d; // value of dPtr is address of d ePtr = &e; // value of ePtr is address of e cout << "\nAt address " << iPtr << ", the value " << *iPtr << " is stored.\n" << "\nAt address " << jPtr << ", the value " << *jPtr << " is stored.\n" << "\nAt address " << dPtr << ", the value " << *dPtr << " is stored.\n" << "\nAt address " << ePtr << ", the value " << *ePtr << " is stored.\n"; // ------------------------------------------------ // NEW STUFF -----------------------------------RJI // ------------------------------------------------ int *pInt = new int; // DYNAMIC ALLOCATION OF NEW int double *pDouble = new double; // DYNAMIC ALLOCATION OF NEW double *pInt = 55; *pDouble = 6.6; cout << "----------------------------------------\n"; cout << "At address " << pInt << ", the value " << *pInt << " is stored.\n" << "\nAt address " << pDouble << ", the value " << *pDouble << " is stored.\n"; delete pInt; // RETURN ALLOC'D int SPACE TO HEAP delete pDouble; // RETURN ALLOC'D double SPACE TO HEAP }