{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture17

Lecture17 - ECS 30 Introduction to Programming and Problem...

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

ECS 30 Introduction to Programming and Problem Solving François Gygi Department of Computer Science image © www.halloween-corner.com

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

View Full Document
Lecture 17 No homework this week: prepare your midterm! Midterm topics: up to Lecture 17 (this lecture). Chapters 1-8.5 Questions/Answers session Friday Nov 4 Today: Chapter 8 Using arrays
Using arrays Array: a collection of variables indexed by an integer double x[8]; Reserves space for 8 double variables x[0] /* first element of array */ x[1] /* 2 nd element */ ... x[7] /* last (eighth) element */

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

View Full Document
Using arrays int x[5]; x[0] x[1] x[2] x[3] x[4] Contiguous in memory
Defining array sizes Array declaration (fixed size) double x[8]; Using a parameter for the array size – Use a macro. (ok) #define SIZE 8 double x[SIZE]; – Use a const int variable. (better) const int size = 8; double x[size]; program read_array.c

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

View Full Document
Arrays as parameters Passing an array as a parameter to a function double sum(double x[], int size) { int i; double s = 0.0; for ( i = 0; i < size; i++ ) s += x[i]; return s; }
Arrays as parameters

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 / 19

Lecture17 - ECS 30 Introduction to Programming and Problem...

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

View Full Document
Ask a homework question - tutors are online