Now compare the two approaches to computing the trade value. The first approach uses an ordinary return value:
double trade_price (struct trade *tptr) { return tptr -> price * tptr -> number; } ... for (counter = 0; counter < limit; ++counter) sum = sum + trade_price(&trades[counter]);
The second approach uses a pointer parameter in combination with the address of a variable's value:
void trade_price (struct trade *tptr, double *result) { *result = tptr -> price * tptr -> number; } ... for (counter = 0; counter < limit; ++counter) { trade_price (&trades[counter], &trade_price_result); sum = sum + trade_price_result; }