September 2001
Beginner
970 pages
23h 20m
English
Suppose you want to write a function that operates on an array. For example, suppose you want a function that returns the sum of the elements of an array. Suppose marbles is the name of an array of int. What would the function call look like? A reasonable guess would be this:
total = sum(marbles); // possible function call
What would the prototype be? Remember, the name of an array is the address of its first element, so the actual argument marbles, being the address of an int, should be assigned to a formal parameter that is a pointer-to-int:
int sum(int * ar); // corresponding prototype
What information does sum() get from this argument? It gets the address of the first element of the array and it learns ...
Read now
Unlock full access