![]() |
![]() |
![]() |
![]() |
![]() |
|
You can hand an array to a function by passing the name of the array as an argument.
Suppose, for example, that you want to define a function,
sum_trade_prices, to be used as follows:
*-- An array name, a pointer
v
sum = sum_trade_prices (trades, limit)
^
*-- Number of trades in array
To define sum_trade_prices, you declare that the first argument is a
pointer to a trade object. That tells the C compiler what it
needs to know to increment the corresponding parameter appropriately inside
sum_trade_prices:
double sum_trade_prices (struct trade *p, int counter) {
double result = 0;
int i;
for (i = 0; i < counter; i++, p++)
result = result + trade_price (p);
return result;
}