Arrays - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Arrays

Description:

Understand the difference between run-time and compile-time arrays. Load array values from a file ... Range of values any set of contiguous vales. Summary ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 14
Provided by: LJ45
Category:
Tags: arrays | compile

less

Transcript and Presenter's Notes

Title: Arrays


1
Arrays
2
Objectives
  • Understand how arrays are used
  • Understand how arrays occupy computer memory
  • Manipulate an array to replace nested decisions
  • Declare and initialize an array
  • Understand the difference between run-time and
    compile-time arrays
  • Load array values from a file

3
Objectives (cont)
  • Search for an array for an exact match
  • Use parallel arrays
  • Force subscripts to remain within array bounds
  • Improve search efficiency by using an early exit
  • Search an array for a range match

4
Understanding Arrays
  • Arrayseries or list of variables in computer
    memory, all of which have the same name but are
    differentiated with special numbers called
    subscripts
  • Subscriptsnumber that indicates the position of
    a particular item within an array

5
How Array Occupy Computer Memory
  • Elementeach separate array variable
  • Size of the Arraynumber of elements an array
    will hold
  • All array elements have the same group name, but
    each individual element also has a unique
    subscript indicating how far away it is from the
    first element

6
Subscript
  • Variable could be used as a subscript as long as
    it is
  • Numeric with no decimal places
  • Initialized by 1
  • Incremented by 1 each time the logic passed
    through the loop

7
Terms
  • Initialization looploop structure that provides
    initial values for every element in any array
  • Run-time array or execution-time arrayarray that
    receives its final values during an actual run,
    or execution, of a program
  • Compile-time arraysone whose final desired
    values are fixed at the beginning of the program
  • Hard codedexplicitly assigned to the array
    elements

8
Using Parallel Arrays
  • Parallel arrayseach element in one array is
    associated with the element in the same relative
    position in the other array

9
Remaining Within Array Bounds
  • Out of Boundsusing a subscript that is not
    within the range of acceptable subscripts
  • Ordering a wrong item number is a frequent error

10
Early Exit
  • Leaving a loop as soon as a match is found
  • Improves the programs efficiency
  • The larger the array, the more beneficial it
    becomes to exit the searching loop as soon as you
    find what youre looking for

11
Range Match
  • Range of valuesany set of contiguous vales

12
Summary
  • An array is a series or list of variables in
    computer memory, all of which have the same name
    but are differentiated with special numbers
    called subscripts
  • When you declare an array, you declare a
    programming structure that contains multiple
    elements
  • You often can use a variable as a subscript to an
    array, replacing multiple nested decisions
  • You can declare and initialize all of the
    elements in an array using a single statement
    that provides a type, a name, and a quantity of
    elements for the array
  • An array whose values are determined during the
    execution of a program is a run-time array, or
    execution-time array
  • You can load an array from a file

13
Summary (cont)
  • Searching through an array to find a value you
    need involves initializing a subscript, using a
    loop to test each array element, and setting a
    flag when a match if found
  • In parallel arrays, each element in one array is
    associated with the element in the same relative
    position in the other array
  • Your programs should ensure that subscript values
    do not go out of bounds, that is take on a value
    out of the range of legal subscripts
  • When you need to compare a value to a range of
    values in an array, you can store either the
    low-or high-end value of each range for comparison
Write a Comment
User Comments (0)
About PowerShow.com