As we saw in Chapter 2, Understanding Program Structure, function parameters in C are call-by-value. In other words, when a function is defined to take parameters, the values the function body receives through them are copies of the values given at the function call. The following code copies the values of two values into function parameters so that the function can use those values in its function body:
double RectPerimeter( double h , double w ) {
h += 10.0;
w += 10.0;
return 2*(w + h) ;
}
int main( void ) {
double height = 15.0;
double width = 22.5;
double perimeter = RectPerimeter( height , width );
}
In this simple example, the RectPerimeter()function takes two parameters—handw—and returns a value that is based on both of them—the perimeter of the rectangle. WhenRectPerimeter()is called, the handwfunction variables are created and the values ofheightandwidthare assigned to them so thathhas a copy of the...