< previous page page_104 next page >

Page 104
whenever you want to use the function, you just make a function call. Here's an example:
#include <iostream.h>
#include <math.h>      // For sqrt() and fabs()
  .
  .
  .
float alpha;
float beta;
  .
  .
  .
alpha = sqrt(7.3 + fabs(beta));
The C++ standard library provides dozens of functions for you to use. Appendix C lists a much larger selection than we have presented here. You should glance briefly at this appendix now, keeping in mind that much of the terminology and C++ language notation will make sense only after you have read further into the book.
Void Functions
In this chapter, the only kind of function that we have looked at is the valuereturning function. C++ provides another kind of function as well. If you look at the Payroll program in Chapter 1, you see that the function definition for CalcPay begins with the word void instead of a data type like int or float:
void CalcPay( ... )
{
    .
    .
    .
}
CalcPay is an example of a function that doesn't return a function value to its caller. Instead, it just performs some action and then quits. We refer to a function like this as a non-value-returning function, a void-returning function, or, most briefly, a void function. In many programming languages, a void function is known as a procedure.
Void functions are invoked differently from value-returning functions. With a value-returning function, the function call appears in an expression. With a void function, the function call is a separate, stand-alone statement. In the Payroll program, main calls the CalcPay function like this:
CalcPay(payRate, hours, wages);

 
< previous page page_104 next page >