{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cpts121-8-2

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

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

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

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

View Full Document
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]
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 */

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

View Full Document
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]
5 CptS 121 L8-2 – 10/14/09 Prof. Chris Hundhausen Parallel Arrays Often, we'd like to associate the values in

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online