At this point, you know that pointer variables and pointer arithmetic
provide an alternate notation for going after array elements. As an
illustration, consider the for
statement that appears in the version
of the analyze_trades
program in Segment 322:
for (counter = 0; counter < limit; ++counter) sum = sum + trade_price(&trades[counter]);
Note that a call to trade_price
resides in the for
statement.
The argument, provided by &trades[counter]
is the address of an
element in the trades array.
You know, however, that you can provide the same address using pointer
arithmetic: trades + counter
is the same address as
&trades[counter]
. Accordingly, you can substitute the following for
the for
statement in Segment 322:
for (counter = 0; counter < limit; ++counter) sum = sum + trade_price(trades + counter);