Functions, Methods, and Arrays
To pass a single array element to a function or method, you specify the array element as an argument in the normal fashion. So if you had a squareRoot function to calculate square roots and wanted to take the square root of averages[i] and assign the result to a variable called sq_root_result, a statement such as this one would work:
sq_root_result = squareRoot (averages[i]);
Passing an entire array to a function or method is an entirely new ballgame. To pass an array, you need to list only the name of the array, without any subscripts, inside the call to the function or method invocation. For example, if you assume that grade_scores has been declared as an array containing 100 elements, the expression
minimum (grade_scores) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access