Home Segments Index Top Previous Next

125: Mainline

In the following program, for example, l's value is 40 before box_car_volume has been entered, l's value is 50 as box_car_volume is executed, and l's value is 40 after the execution of box_car_volume.

#include  
// Define box_car_volume first: 
double box_car_volume (double h, double w, double l) { 
  cout << "The value of l inside box_car_volume is " 
       << l << endl; 
  return h * w * l; 
} 
// Then, define main: 
main ( ) { 
  double l = 40.0, volume; 
  cout << "The value of l outside box_car_volume is " 
       << l << endl; 
  volume = box_car_volume (10.5, 9.5, l + 10.0); 
  cout << "The volume of a stretched box car is " 
       << volume << endl; 
  cout << "The value of l outside box_car_volume is still " 
       << l << endl; 
} 
--- Result --- 
The value of l outside box_car_volume is 40 
The value of l inside box_car_volume is 50 
The volume of a stretched box car is 4987.5 
The value of l outside box_car_volume is still 40