Chap11 - 1 Chapter 11 2 Outline One-Dimensional Arrays...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Chapter 11 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 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 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]; 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) 10 One-Dimensional Arrays (continued) 11...
View Full Document

Page1 / 37

Chap11 - 1 Chapter 11 2 Outline One-Dimensional Arrays...

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

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