- Code: Select all
001 int* intPtr = new int;
002 whilte ( intPtr != 0 )
003 {
004 intPtr = new int;
005 cin >> *intPtr;
006 cout << *intPtr + 10;
007 delete intPtr;
008 intPtr = 0;
009 } // end while
010 for ( int i = 0; intPtr == 0; ++i )
011 {
012 intPtr = new int;
013 *intPtr = i;
014 cout << intPtr;
015 intPtr = 0;
016 { // end for
001 Creates a pointer to an integer on the heap
002 Initializes loop with condition while the pointer is not 0
004 Reassigns the pointer to a new memory location on the heap - old memory location is lost (leaked)
005 Takes a value from the user and puts it into the memory location that the pointer points to
006 Outputs that value plus 10
007 Deletes the int on the heap that the pointer pointed to
008 Assigns the pointer to NULL
009 Exits loop because pointer is no longer not equal to 0
010 Initializes for loop creating variable i and defining it with 0, loop ends if pointer is equal to 0, increments i by 1 BEFORE each iteration
012 Pointer now points to a new int object on the heap
013 Gives the int object the value of i (which is 1)
014 Outputs the address of the pointer
015 Assigns pointer to point to nowhere (NULL) - FOR CONDITION TO END IS NOW TRUE
016 Exits for loop - Condition is true
I think that's right...