CS 150 - Intro to Programming - Fall 2001
Lab Exercise 14
(last one !!!)

Topics

1. Given the declarations

      double *p, *q;

Consider each of the following code fragments independently. Describe the value of *p and *q after each fragment. If the code fragment results in an lost reference, a dangling pointer, and/or a memory leak, say so. Paste each code segment into a C++ program, enable the debugger and note the results.


a.

p = new double;
*p = 12.5;
q = p; 
delete p;

d.

p = new double;
q = new double;
*p = 12.5;
q = new double;
*q = *p;

b.

p = new double;
q = new double;
*p = 12.5;
*q = *p;

e.

p = new double;
q = new double;
*p = *p + *q;
delete q;

c.

p = new double;
q = new double;
*p = 12.5;
q = p;
 

2. Write a program that asks the user to enter an integer. Then dynamically allocate an array of int's based on the users entry. Use a for loop to assign each element of the new array a different value. Use another for loop to output the elements of the array.


Turn in you program from part 2.(YourLastNameLab14)