Why is the return type not used


Next:LibrariesUp:Functions and Operators Previous:Functions and Operators

Functions with no arguments or return value, void

The keyword is used like a type, but it is not a real type. It is used to identify functions that do not have a return value. This is sometimes useful for functions whose effect is only to output something on the screen or to manipulate an argument in a certain way.

void error (string message) {cout << "error occurred:" << message << "\ n"; }

Functions without arguments can also be useful. In C ++, a function without arguments is indicated by an empty argument list. A typical example is a pseudo-random number generator that returns a different number each time it is called. The C library provides a (bad) generator that is declared (in):

void srand (unsigned int seed); int rand (void); This is used in such a way that you first select a sequence of random numbers by calling the function with a positive integer. Then you get a new, whole number back each time you call up.
& copy R.Hilfer et al., ICA-1, Univ. Stuttgart
28.6.2002