The void Type
void is C's way of saying "no type here." It is not a type you can store a value in — instead, it is used in a handful of specific places to tell the compiler that something is intentionally empty, absent, or type-agnostic.
Functions that return nothing
The most common use of void is as a function's return type, meaning the function does not produce a value that the caller can use. Instead of return value;, such a function either falls off the end of its body or uses a bare return; to exit early.
#include <stdio.h>
void print_banner(const char *title) {
printf("=== %s ===\n", title);
return; /* optional here, allowed with no value */
}
int main(void) {
print_banner("Welcome");
return 0;
}=== Welcome ===
Functions that take no parameters
In C, an empty parameter list, int main(), technically means "this function takes an unspecified number of arguments" under older rules — not the same as "this function takes no arguments." Writing void explicitly inside the parentheses, as in int main(void), tells the compiler and anyone reading the code that the function genuinely accepts zero arguments, and lets the compiler catch a call that mistakenly passes arguments.
int get_random_number(void) { /* takes no arguments, by design */
return 4; /* chosen by fair dice roll */
}
int main(void) {
int n = get_random_number();
return 0;
}void* — a generic pointer (preview)
void* is a pointer that can hold the address of any data type, but without knowing what type of data lives there. It is used throughout the standard library — malloc returns a void*, and functions like memcpy and qsort accept void* parameters so that they can work with any data type. We cover void* pointers in full detail later, in the dedicated Void Pointers page.
#include <stdlib.h>
int main(void) {
void *raw = malloc(10 * sizeof(int)); /* malloc returns void* */
int *numbers = (int *)raw; /* cast to a usable pointer type */
free(numbers);
return 0;
}You cannot declare a variable of type void
/* void x; */ /* INVALID: cannot declare a variable of type void */ void *ptr = NULL; /* VALID: a pointer *to* void is fine */
voidas a return type means a function returns no value.int main(void)explicitly declares that main takes zero arguments.void*is a generic pointer that can point to any type, widely used in the standard library.You can never declare an actual variable of type void — only pointers to void.