1. | What is the difference between an array element and a variable? |
|
2. | What is an array of pointers? |
|
3. | How do you assign an address to an element of a pointer array? |
|
4. | What is an array of pointers to pointers? |
|
5. | How do you assign a value to an element of an array of pointers to pointers? |
|
6. | How do you display the contents of the memory addresses stored in an element of a pointer array? |
|
7. | Why would you use an array of pointers to pointers? |
|
8. | How do you declare an array? |
|
9. | How do you display the contents of the memory addresses stored in an element of an array of pointers to pointers? |
|
10. | How are elements of an array stored in memory? |
|
Answers
1. | The name of a variable references one memory location. The name of an array references one or multiple memory locations when used in conjunction with an index. If a programmer needs to access multiple variables , the programmer must explicitly specify variable names within the program. If a programmer needs to access multiple elements of array, the programmer can use the array name followed by an index value within a for loop. |
2. | An array of pointers is an array whose elements store memory addresses of variables or elements of another array. |
3. | You assign a memory address to an element of a pointer array by using the address operator, which is the ampersand (&), in an assignment statement such as ptLetters[0] = &letters[2]; |
4. | An array of pointers to pointers is an array whose elements can store a memory address. This memory address is the memory address of either a pointer variable or an element of a pointer array. |
5. | You assign a value to an element of an array of pointers to pointers by using the address operator, as shown here. However, the value must be a memory address of a pointer. ptPtLetters[0] = & ptLetters[0]; |
6. | You display the contents of the memory addresses stored in an element of a pointer array by preceding the element with an asterisk, as shown here: cout << * ptLetters[0] << endl; |
7. | You would use an array of pointers to pointers to reorder large amounts of data stored in memory without having to move the data. Instead of moving the data, you reorder reference to the data s memory address. |
8. | An array is declared by specifying the data type, array name, and number of elements contained in the array, as shown here: char letters[3]; |
9. | You display the contents of the memory addresses indirectly referenced in an element of an array of pointers to pointers by preceding the array name with two asterisks , as shown here: cout << * ptPtLetters[0] << endl; |
10. | Elements of an array are stored sequentially in memory. |