CMPT 127 Lecture Notes - Lecture 21: Wasn

70 views2 pages

Document Summary

Since array variables can be used like pointers, you can pass them into functions as such. The two versions of the array_max function have different syntax for passing the array, but are otherwise identical. You should almost always use the array-bracket syntax version ( int arr[] ) since it tells the human reader that an array is expected. Note that we had to pass the length of the array into both versions. C arrays do not know how long they are. Notice also that we used an unsigned int for the array length. This is sensible because negative-length arrays can not exist. Since the compiler will ensure that len does not have a negative value, we avoid a whole class of possible bugs. In general we always use the most restrictive type available so that the compiler can help us notice such mistakes.

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