Worksheet W.A.31.1                                                           Name  ____________________________________

 POINTER TYPES

 For questions 1-4 , assume that the following declaration applies:

 int  *first, *second, *third;

 1.     Allocate memory and store the value of 15 in *first.

  

 

2.     Assuming that memory has already been allocated for first, second, and third:

 

a.     Assign the integer value pointed to by first to the location pointed to by third.

 

 

b.     Make third point to the same location as second.

 

 

 

 3.     Explain what is wrong with each of the following statements:

             a.     first = 5;

 

b.     first = second + third;  

 

Define the following terms:  

4.     Pointer variable -

  

5.     Indirection -

 

6.     Dereference -  

 

7.     Address -

 

8.     Static data structure -

 

9.     Dynamic data structure -

 

10. Write a complete program which does the following: 

 a.     Declares a pointer variable which points to an integer.

b.     Allocates memory using the new command to store an integer in the memory location pointed to by the pointer variable.

c.     Reads an integer from the keyboard, stores it in the location pointed to by the pointer variable, and prints out the integer.

d.     Disposes of the memory location using the delete command.

    As you write this program, include in your documentation a definition of the commands new  and delete.  Use your C++ editor to write, compile, test, and print out this program.  Staple your source code to this page.