void
is a data type with no values. It is also an incomplete data type that cannot be completed. When used as a return type for a function, it indicates that the function does not return a value:
void foo(int x);
When used as a parameter list, it indicates that the function takes no arguments:
void bar(void);
This is different from an empty parameter list, which indicates that the function takes an unspecified number of arguments (in C; in C++, an empty parameter list is the same as using void
):
void bletch();
No object (variable) can be typed void
. However, you can declare pointers of type void *
: these are "generic" pointers, and can be converted to and from other pointer types without an explicit cast. The standard memory allocation functions malloc
, calloc
, and realloc
all return void *
:
double *darr = malloc(sizeof *darr * rows);
In a hosted implementation (basically, anything with an operating system), main
must be declared as
int main(void)
or
int main(int argc, char **argv) // the parameter names can be whatever you want,
// but argc and argv are the usual convention;
// char **argv is equivalent to char *argv[]
or in some other implementation-defined manner; an implementation may accept
void main()
as a legitimate signature for main
, but it must explicitly document that somewhere.