CEng140 - Week4-1

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

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

CEng-140 Week 4-1

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

View Full Document
Midterm Date : 23 rd of November, 2010 Time : 17:30 Location : To be announced
Today Collection of data Arrays

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

View Full Document
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]
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]++;

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

View Full Document
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};
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/06/2011 for the course CENG ceng 230 taught by Professor Prof.osmanwxw during the Spring '10 term at Middle East Technical University.

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