Chapter 9

 < Day Day Up > 



Chapter 8

  1. An array is a ______________ allocation of memory to _____________ objects.

    contiguous / homogeneous

  2. A static array name is what type of pointer?

    const pointer

  3. (T/F) An array name points to the first element of the array.

    TRUE

  4. How are multi-dimensional arrays stored in memory.

    Row major order

  5. Multi-dimensional arrays are arrays of ______________.

    arrays

  6. What determines the size of an allocation unit?

    The data type.

  7. How does a dynamically allocated array differ from a statically allocated array?

    The elements of a dynamically allocated array are stored in heap memory.

  8. List at least four types of objects an array can contain.

    Fundamental data types

    User-defined data types

    Pointers to fundamental data types

    Pointers to user-defined types

    Pointers to members

    Enumerated types

    Other arrays

  9. Describe the two methods available to access array elements.

    Subscript method

    Pointer arithmetic method

  10. To what values will the array elements be initialized to in the following declaration:

    int int_array[25]; 

    The array will contain garbage values.

  11. To what values will each array element be initialized to in the following declaration:

    int int_array[25] = {1,2,3}; 

    The first three elements will be 1, 2, 3, and the rest will be initialized to 0.

  12. What is the difference between the new operator and the new[] operator?

    The new operator allocates memory for new objects; the new[] operator allocates memory for arrays

  13. Why is it important to release dynamically allocated array memory with the delete[] operator?

    Because the delete[] operator is the array equivalent to the delete operator. Any memory allocated with new[] should be released with delete[].

  14. List and discuss the steps required to create a single-dimensional dynamic array.

    Declare a pointer to the type of array elements

    Create the array with the new[] operator

    Create each element object as required with the new operator

    ---- when done with array

    Delete each element object with the delete operator

    Delete the array pointer with the delete[] operator

  15. Discuss the two methods for creating multi-dimensional dynamic arrays. Which method would you prefer to use and why?

    The first method is to statically allocate the smallest set of elements and dynamically allocate the largest

    The second method is to dynamically allocate all dimensions of the multi-dimensional array. A multi-dimensional array is just an array of arrays.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net