Chp~11 - C+ PROGRAMMING Chapter 11 Arrays What Is an Array?...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ PROGRAMMING Chapter 11 Arrays What Is an Array? Figure 11.1. Array Elements Listing 11.1. Using an integer array . Writing Past the End of an Array Listing 11.2. Writing past the end of an array . Fence Post Errors Figure 11.2. Initializing Arrays Declaring Arrays Listing 11.3. Using consts and enums in arrays . Arrays Arrays of Objects Listing 11.4. Creating an array of objects . Multidimensional Arrays Figure 11.3. Initializing Multidimensional Arrays Listing 11.5. Creating a multidimensional array . Figure 11.4. A Word About Memory Arrays of Pointers Listing 11.6. Storing an array on the free store . Declaring Arrays on the Free Store A Pointer to an Array Versus an Array of Pointers Pointers and Array Names Listing 11.7. Creating an array by using new . Deleting Arrays on the Free Store char Arrays Listing 11.8. Filling an array . Listing 11.9. Filling an array. strcpy() and strncpy() Listing 11.10. Using strcpy(). , Listing 11.11. Using strncpy(). String Classes Listing 11.12. Using a String class . Linked Lists and Other Structures Figure 11.5. Listing 11.13. Implementing a linked list . Figure 11.6. Array Classes Summary , , Quiz , Exercises
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter 11 Arrays In previous chapters, you declared a single int , char , or other object. You often want to declare a collection of objects, such as 20 int s or a litter of CAT s. ToChapter, you learn What arrays are and how to declare them. What strings are and how to use character arrays to make them. The relationship between arrays and pointers. How to use pointer arithmetic with arrays. What Is an Array? An array is a collection of data storage locations, each of which holds the same type of data. Each storage location is called an element of the array. You declare an array by writing the type, followed by the array name and the subscript. The subscript is the number of elements in the array, surrounded by square brackets. For example, long LongArray[25]; declares an array of 25 long integers, named LongArray . When the compiler sees this declaration, it sets aside enough memory to hold all 25 elements. Because each long integer requires 4 bytes, this declaration sets aside 100 contiguous bytes of memory, as illustrated in Figure 11.1. Figure 11.1. Declaring an array. Array Elements You access each of the array elements by referring to an offset from the array name. Array elements are counted from zero. Therefore, the first array element is arrayName[0] . In the LongArray example, LongArray[0] is the first array element, LongArray[1] the second, and so forth. This can be somewhat confusing. The array
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2012 for the course CS 131 taught by Professor Clayton during the Spring '08 term at Bethune Cookman.

Page1 / 35

Chp~11 - C+ PROGRAMMING Chapter 11 Arrays What Is an Array?...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online