cpts121-8-2 - CptS 121 Fall 09 Lecture 8-2 HK Chapter 8:...

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

View Full Document Right Arrow Icon
1 CptS 121 L8-2 – 10/14/09 Prof. Chris Hundhausen CptS 121 Fall ‘09 Lecture 8-2 HK Chapter 8: Arrays Lecture Outline I. Introduction to Arrays
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 CptS 121 L8-2 – 10/14/09 Prof. Chris Hundhausen Declaring an Array Arrays are declared in much the same way as variables: int a[6]; declares an array a with 6 cells that hold integers: Notice that array indexing begins at 0. 10 12 0 89 1 91 a[0] a[1] a[2] a[3] a[4] a[5]
Background image of page 2
3 CptS 121 L8-2 – 10/14/09 Prof. Chris Hundhausen Declaring an Array (cont.) We can declare arrays alongside simple variables: int students[100], count, teachers[50]; double gpa[100], average; char ch, name[100]; /* name is actually a string */
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 CptS 121 L8-2 – 10/14/09 Prof. Chris Hundhausen Manipulating Array Cells Assuming the previous array: all of the following statements are valid: a[0] = 4; /* changes the value of a[0] from 10 to 4 */ a[2] += 2; /* sets the value of a[2] to 2 */ a[5] = a[3] – a[4]; /* sets the value of a[5] to 88 */ 10 12 0 89 1 91 a[0] a[1] a[2] a[3] a[4] a[5]
Background image of page 4
5 CptS 121 L8-2 – 10/14/09 Prof. Chris Hundhausen Parallel Arrays Often, we'd like to associate the values in one array with those in another array
Background image of page 5

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

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

Page1 / 14

cpts121-8-2 - CptS 121 Fall 09 Lecture 8-2 HK Chapter 8:...

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

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