# Chap11 - Chapter 11 1 Outline One-Dimensional Arrays Array...

• Notes
• 626315127_ch
• 37

This preview shows pages 1–11. Sign up to view the full content.

1 Chapter 11

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

2 Outline One-Dimensional Arrays Array Initialization Declaring and Processing Two- Dimensional Arrays Applications in searching and sorting
3 One-Dimensional Arrays One-dimensional array: a list of related values with the same data type, stored using a single group name (called the array name ) Syntax: dataType arrayName[number-of-items] By convention, the number of items is first declared as a constant, and the constant is used in the array declaration

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

4 One-Dimensional Arrays (continued) Examples: const int NUMELS = 6; int volts[NUMELS]; const int ARRAYSIZE = 4; char code[ARRAYSIZE];
5 One-Dimensional Arrays (continued) element : an item in the array Array storage of elements is contiguous index (or subscript ) of an element: the position of the element within the array Indexes are zero-relative To reference an element, use the array name and the index of the element

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

6 One-Dimensional Arrays (continued) Index represents the offset from the start of the array Element is also called indexed variable or subscripted variable Subscripted variable can be used anywhere that a variable can be used Expressions can be used within the brackets if the value of the expression yields an integer value is within the valid range of subscripts
7 One-Dimensional Arrays (continued) All of the elements of an array can be processed by using a loop The loop counter is used as the array index to specify the element Example: sum = 0; for (i=0; i<5; i++) sum = sum + temp[i];

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

8 One-Dimensional Arrays (continued) Input and Output of Array Values Array elements can be assigned values interactively using a cin stream object Out of range array indexes are not checked at compile-time, but may produce run-time errors or may overwrite a value in the referenced memory location, causing other errors Array elements can be displayed using the cout stream object
9 One-Dimensional Arrays (continued)

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

10 One-Dimensional Arrays (continued)
This is the end of the preview. Sign up to access the rest of the document.
• Spring '09
• BETANCOURT
• Sort, Array, Search algorithm, array element, one-dimensional arrays

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern