If we wanted to change the values of parameters so that they are also changed after the function returns, we can use pointers to do so. We would assign the address of the values we want to modify to pointer variables and then pass the pointer variables into the function. The addresses (which can't change anyway) will be copied into the function body and we can dereference them to get the values we want. This is called passing by reference. We would modify our program as follows:
double RectPerimeter( double* pH , double *pW )
{
*pH += 10.0;
*pW += 10.0;
return 2*( *pW + *pH ) ;
}
int main( void )
{
double height = 15.0;
double width = 22.5;
double* pHeight = &height;
double* pWidth = &width;
double perimeter = RectPerimeter( pHeight , pWidth );
}
The RectPerimeter()function now takes two pointers—pHandpW. When the function is called,pHandpWare created and the values ofpHeightandpWidthare assigned to each.pHhas...