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

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

View Full Document Right Arrow Icon
1 Chapter 11
Image of page 1

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

View Full Document Right Arrow Icon
2 Outline One-Dimensional Arrays Array Initialization Declaring and Processing Two- Dimensional Arrays Applications in searching and sorting
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
4 One-Dimensional Arrays (continued) Examples: const int NUMELS = 6; int volts[NUMELS]; const int ARRAYSIZE = 4; char code[ARRAYSIZE];
Image of page 4
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
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 6
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];
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 8
9 One-Dimensional Arrays (continued)
Image of page 9

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

View Full Document Right Arrow Icon
10 One-Dimensional Arrays (continued)
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern