An incomplete type used as syntactic place-holder for the return type of a method/function when no value is returned.
Programming languages derived from C or Algol68, like C++, C#, Java, etc., may define the return type of methods/functions as void
when the method/function does not return a value, but simply completes execution.
An example of its use in Java, compared to a non-void method, is:
int nonVoidMethod {
// do something
return 0; // return a value to the caller
}
void voidMethod {
// do something
return; // no value allowed to be returned from a void method
// a "return" statement is not required
}
Although void
is used as a type, it's an incomplete type:
In some languages, such as Java and Algol68,
void
is only a keyword used as a return type. It is not considered as a valid type in other language constructs.Other languages, like C and C++, consistently define
void
as a type with an empty set of values. This allows its use for example in compound type constructs (void pointers). But novoid
objects can be instantiated.