|
|
 |
|
|
|
|
int someVal;
float velocity[10]; |
|
|
|
 |
|
|
|
|
and the declarations in Question 1, |
|
|
|
 |
|
|
|
|
a. how would you make intPtr point to someVal and then use intPtr to store 25 into someVal? |
|
|
|
 |
|
|
|
|
b. how would you make arrPtr point to velocity and then use arrPtr to store 6.43 into the third element of velocity? (pp. 968979) |
|
|
|
 |
|
|
|
|
RecType oneRec; |
|
|
|
 |
|
|
|
|
and the declarations in Question 1, |
|
|
|
 |
|
|
|
|
a. how would you make recPtr point to oneRec? |
|
|
|
 |
|
|
|
|
b. what are two different expressions using recPtr that will store 120.5 into the weight member of oneRec? (pp. 968979) |
|
|
|
|
|
|
|
|
4. a. In a single statement, declare a pointer variable named dblPtr and initialize it to the address of a newly created dynamic variable of type double. Then, in a second statement, store 98.32586728 into the dynamic variable. |
|
|
|
 |
|
|
|
|
b. In a single statement, declare a pointer variable named list and initialize it to the base address of a newly created dynamic array of 50 int elements. Then give a section of code that will zero out the array. (pp. 979986) |
|
|
|
|
|
|
|
|
5. Given the variables dblPtr and list of Question 4, show how to deallocate the dynamic data pointed to by dblPtr and list. (pp. 979986) |
|
|
|
|
|
|
|
|
6. Given the declaration and initialization |
|
|
|
 |
|
|
|
|
float delta = -42.7; |
|
|
|
 |
|
|
|
|
how would you declare a variable gamma to be of type reference to float and initialize it to contain the memory address of delta? (pp. 987990) |
|
|
|
|
|
|
|
|
7. Using the variable gamma of Question 6, how would you store the value 12.9 into delta? (pp.987990) |
|
|
|
|
|
|
|
|
8. Which kind of copy operationdeep or shallowcopies one pointer to another without copying any pointed-to data? (pp. 990997) |
|
|
|
|
|
|
|
|
9. As defined by C++, assignment (using an assignment expression) and initialization are two different things. What are the three ways in which one C++ class object is initialized by another? (p. 998) |
|
|
|
|
|
|
|
|
10. In designing a C++ class whose class objects point to dynamic data, what are the four member functions you should provide? (p. 1001) |
|
|
|
|
|
|
|
|
11. What are two ways in which pointers may be used to improve program efficiency? (pp.1001,1034) |
|
|
|
|
|
|
|
|
1. int* intPtr;
float* arrPtr;
RecType* recPtr;
2. a. intPtr = &someVal;
*intPtr = 25;
b. arrPtr = velocity; (or arrPtr = &velocity[0];)
arrPtr[2] = 6.43;
|
|
|
|
|
|