Sams Teach Yourself C++ in 21 Days

(singke) #1
Q Can I combine arrays?
A Yes. With simple arrays, you can use pointers to combine them into a new, larger
array. With strings, you can use some of the built-in functions, such as strcat,to
combine strings.
Q Why should I create a linked list if an array will work?
A An array must have a fixed size, whereas a linked list can be sized dynamically at
runtime. Appendix E provides more information on creating linked lists.
Q Why would I ever use built-in arrays if I can make a better array class?
A Built-in arrays are quick and easy to use, and you generally need them to build
your better array class.
Q Is there a better construct to use than arrays?
A On Day 19, “Templates,” you learn about templates as well as the Standard
Template Library. This library contains templates for arrays that contain all the
functionality you will generally need. Using these templates is a safer alternative to
building your own.
Q Must a string class use a char *to hold the contents of the string?
A No. It can use any memory storage the designer thinks is best.

Workshop ............................................................................................................


The Workshop provides quiz questions to help you solidify your understanding of the
material covered and exercises to provide you with experience in using what you’ve
learned. Try to answer the quiz and exercise questions before checking the answers in
Appendix D, and be certain you understand the answers before continuing to tomorrow’s
lesson.

Quiz ................................................................................................................



  1. What are the first and last elements in SomeArray[25]?

  2. How do you declare a multidimensional array?

  3. Initialize the members of an array declared as SomeArray[2][3][2].

  4. How many elements are in the array SomeArray[10][5][20]?

  5. How does a linked list differ from an array?

  6. How many characters are stored in the string “Jesse knows C++”?

  7. What is the last character in the string “Brad is a nice guy”?


446 Day 13

Free download pdf