APCO 1P93 Lecture Notes - Lecture 10: Array Data Structure, Bounds Checking, Linear Search

53 views4 pages

Document Summary

Instead of creating multiple similar variables such as employee1, employee2, employee3 and so on : it"s more efficient to create just one variable. Declare real salesamounts[7: the number in the [ ] is the size of the array. The storage locations in an array are elements. Each element of the array has a unique number called a subscript that identifies it the subscript starts at 0 in most languages. Assigning values can be done individually using a subscript . But, it is much more efficient to use a loop to step through the array. Arrays can be initialized to 0 or specific values. Array bounds checking should be performed to avoid use of an invalid subscript. Days[7] = saturday is invalid because there is no 7 index: a common error is running a loop one time more than is necessary, exceeding the bound of the array, off-by-one error.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents