MAT 21B Lecture 15: Lecture 15
Lecture 15
See code line on powerpoint
Pointer and iteration
- Use of a pointer variable for iterating through an array
o Access current element through dereferencing
o Increment pointer to move to next element
- Incrementing a pointer adds the seize of the pointed data
Array Size
- Sizeof ( ) returns the overall size of an array
- Dividing the array size by the size of an element, gives the numer of element
Passing arrays of arguments
- Arrays always decay into simple pointers when passed as arguments
- GCC warns when using sizeof( ) on a decayed array
- Functions always modify original array … not copies
- Cannot return a local array from a function
o All local variables disappear when a function returns
Searching
- Determine the location of a particular value in an array
Sorting
- Inefficient version of election sort
- Vary basic sorting algorithm
o Find smallest number of each position in the array successively
o Compare with all remaining number successively
find more resources at oneclass.com
find more resources at oneclass.com
beigecamel74 and 41 others unlocked
83
MAT 21B Full Course Notes
Verified Note
83 documents
Document Summary
Use of a pointer variable for iterating through an array: access current element through dereferencing, increment pointer to move to next element. Incrementing a pointer adds the seize of the pointed data. Sizeof ( ) returns the overall size of an array. Dividing the array size by the size of an element, gives the numer of element. Arrays always decay into simple pointers when passed as arguments. Gcc warns when using sizeof( ) on a decayed array. Functions always modify original array not copies. Cannot return a local array from a function: all local variables disappear when a function returns. Determine the location of a particular value in an array. Vary basic sorting algorithm: find smallest number of each position in the array successively, compare with all remaining number successively. Arrays with two or more dimension: tables, matrices, charts etc.