MAT 21B Lecture 14: Lecture 14

11 views2 pages
School
Department
Course
Professor
Lecture 14
See powerpoint for code lines
Dynamic size
- The size of the initialization list determines the number of elements
Indexing
- Any expression that produces an integer can be used as subscript
- As long as subscript stays within bounds (see powerpoint for code line)
Loops
- Very often arrays are meant to be sequentially accessed
o For loop is the perfect repetition structure
o Use of a constant for the array size is always recommended
Bounds
- The behavior of out of bound access is difficult to predict
- Segmentation fault errors always come from accessing a memory location that
doesn’t contain a valid object
Pointer constant
- Each element has its own memory address
- Addresses are 4byte apart
- Value associated to the array name is an address
o It’s a pointer
o But cannot be reassigned to another address: pointer constant
o Indexes are distances from this pointer
- A pointer variable can be used like an array
o Pointer itself points on the first element
o Index gives the distance from first element
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in
beigecamel74 and 41 others unlocked
MAT 21B Full Course Notes
83
MAT 21B Full Course Notes
Verified Note
83 documents

Document Summary

The size of the initialization list determines the number of elements. Any expression that produces an integer can be used as subscript. As long as subscript stays within bounds (see powerpoint for code line) Very often arrays are meant to be sequentially accessed: for loop is the perfect repetition structure, use of a constant for the array size is always recommended. The behavior of out of bound access is difficult to predict. Segmentation fault errors always come from accessing a memory location that doesn"t contain a valid object. Each element has its own memory address. Value associated to the array name is an address: it"s a pointer, but cannot be reassigned to another address: pointer constant, indexes are distances from this pointer. A pointer variable can be used like an array: pointer itself points on the first element, index gives the distance from first element.

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