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, ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.