Home Segments Index Top Previous Next

126: Mainline

Because parameters are just variables that happen to be initialized by argument values, you can change the value of any parameter using an assignment statement. For example, you could amend the doubling_time function as follows:

double doubling_time (double r) { 
  /* At this point, r's value is the rate expressed as a percentage */ 
  r = r / 100.0; 
  /* Now r's value is the rate expressed as a fraction */ 
  r = log (2.0) / log (1.0 + r); 
  /* Now r's value is the result of the doubling-time computation */ 
  return r; 
} 

However, using r to hold three different values is bad programming practice, because such use associates r with multiple meanings.