CEng140 - Week4-1 - CEng-140 Week 4-1 Midterm Date: 23rd of...

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

View Full Document Right Arrow Icon
CEng-140 Week 4-1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Midterm Date : 23 rd of November, 2010 Time : 17:30 Location : To be announced
Background image of page 2
Today Collection of data Arrays
Background image of page 3

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

View Full DocumentRight Arrow Icon
Arrays of Numerical Values Array Declaration: type name[SIZE]; Ex: int a[10]; Length: 10 Size: 10 x sizeof(int) Location of a: the first element of a; i.e., a[0] Ex: float b[20]; Length: 20 Size: 20 x sizeof(float) a a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]
Background image of page 4
Accessing Array Elements /* declaration */ int a[10]; /* I can use the elements of an array like a variable */ int b = a[8]; int c = 25 + a[2] - a[8] / a[0]; /* Like a variable, I can assign values to the elements */ a[2] = 25; a[i] += 25 a[2]++;
Background image of page 5

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

View Full DocumentRight Arrow Icon
Initializing Arrays /* The following two are equivalent */ int a[3] = {1, 2, 3}; int a[] = {1, 2, 3}; float c[] = {.1 2.2 0.3}; /* If the number of initializers is less than the size of the array, the remaining ones are set to zero */ int a[8] = {1, 2, 3}; int a[8] = {1, 2, 3, 0, 0, 0, 0, 0};
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

CEng140 - Week4-1 - CEng-140 Week 4-1 Midterm Date: 23rd of...

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

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