{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# unit08mp - Course Philosophy Dr Pryor FAQ's TA Page Office...

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

Course Philosophy Dr. Pryor FAQ's TA Page Office Hours Other Resources Syllabus Tutorials Countdown to the due date: 35 days, 2 hours, 27 minutes Home » 08 bam2734 My account Log out Test Center

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

View Full Document
Units and Reviews 00 01 02 03 04/R1 05 06 07 08 Unit 08 Arrays Unit Objectives Learn how to create an array of data types. Learn how pointers and addresses make it easy to move around in an array. Learn how to pass arrays to a function. Learn how to create dynamic arrays. Introduction What techniques do you have at your disposal right now if you wanted to store the value of the high temperature for every day in 2007? As of now, you would have to create 365 variables which is unrealistic. We need a way to store the high temperatures in a single variable structure that stores all the high temperatures and allows us easily access them. We can look up the high temperature on a given day by indexing to the day of interest. This structure is called an Array which stores an array of numbers. How many? You decide. We can also
easily create multidimensional arrays. For example, instead of just storing the high temperature for each day (which would be 365 x 1 array) we could store the temperature recorded at the top of each hour in a two dimensional array (i.e. 365 x 24 array) Once populated, we can easily write a program that looks up the temperature at 3:00 pm on August 5th for example. In this unit, we will learn how to create and manipulate the values in arrays. We also need to learn how to pass them to functions. We will find out that a basic understanding of pointers and memory allocation will make arrays easier to understand and use in our programs. But first. ... Task 0 - Constant Variables This task is so simple, I am calling it Task 0. Let's say there is, for example, a variable in your program to store the constant for the acceleration of gravity. float g = 9.81; We know that the variable g is a constant and we don't want it to accidentally change its value while we execute the program. In fact, it would be nice if the compiler thought it was illegal to change the value. If that is what we want, then we simply declare the variable to be a constant or const . const float g = 9.81; By doing that, we ensure that if we compile the code below, the compiler returns an error. int main(void) { const float g = 9.81; g = 32.2; //compile returns an error for this line. return 1; } As programs grow more complicated, using constants for variables whose values you do not want to change helps the compiler help you. Task 1 - What is an array? Sometimes a bunch of numbers belong just together. Sometimes we need to group them together for sanity's sake. For example, what if I asked you write a program to store the height in centimeters of every player on the football team? That could easily mean over 100 variables! Programs could get long and confusing very quickly. Sometimes, its not just the number of variables but that the variables are related. For example, what

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

unit08mp - Course Philosophy Dr Pryor FAQ's TA Page Office...

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

View Full Document
Ask a homework question - tutors are online