Home Segments Index Top Previous Next

103: Mainline

Some functions do not return values used in other computations. Instead, they are executed for some other purpose, such as displaying a value.

Accordingly, C allows you to use the void symbol as though it were a data type for return values. When C sees void used as a return value data type, C knows that nothing is to be returned.

For example, in the following program, the display of a trade's total price is handled in the display_trade_price function, so there is no value to be returned. Accordingly, void appears instead of a data-type name in the definition of display_trade_price, and display_trade_price contains no return statement:

#include   
/* Define display_trade_price first */ 
void display_trade_price (double p, int n) { 
  printf ("The total value of the trade is %f.\n", p * n); 
} 
/* Then, define main */ 
main ( ) { 
  double price = 10.2; 
  int number = 600; 
  display_trade_price (price, number); 
} 
--- Result --- 
The total value of the trade is 6120.000000.