Home Segments Index Top Previous Next

320: Mainline

Actually, few C programmers would write (*tptr).price to access the value of the price structure variable. Instead, most would take advantage of the structure-pointer operator, ->, which you can think of as a shorthand that takes the place of both the dereferencing operator and the structure-member operator. The following, therefore, are equivalent:

                 Equivalent 
(*tptr).price   <---------->   tptr -> price 

Thus, the structure-pointer operator takes the place of two other operators and eliminates the need for precedence-defeating parentheses:

double trade_price (struct trade *tptr) { 
  return (tptr -> price) * (tptr -> shares); 
}