CMPT 127 Lecture Notes - Lecture 21: Wasn
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.