Next: , Previous: , Up: Primitive Types   [Contents][Index]


11.4 The Void Type

The data type void is a dummy—it allows no operations. It really means “no value at all.” When a function is meant to return no value, we write void for its return type. Then return statements in that function should not specify a value (see return Statement). Here’s an example:

void
print_if_positive (double x, double y)
{
  if (x <= 0)
    return;
  if (y <= 0)
    return;
  printf ("Next point is (%f,%f)\n", x, y);
}

A void-returning function is comparable to what some other languages call a “procedure” instead of a “function.”