void The void type and generic pointers
void The void type and generic pointers
void is incomplete and valueless, for functions with no result or parameters. void * addresses only objects; dereferencing and void objects are invalid.
| Category | Type specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
void func(void);
void *p;
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
value = 42
🏷️ Related type specifiers
📚 Related Tutorials
❓ FAQ
QAre int main(void) and int main() equivalent?
AIn C89, C99, and C11 prototype semantics, void explicitly specifies no parameters, whereas empty parentheses provide no parameter information. For a main definition, prefer int main(void), the standard no-argument form.
QWhy can't a void pointer be dereferenced or used in pointer arithmetic?
Avoid is an incomplete type with no object size or value type to read. It therefore cannot be dereferenced directly, and standard C does not support void-pointer arithmetic. Convert it to the correct object-pointer type first.
QCan a void function contain a return statement?
AYes, return; can exit the function early, but return with an expression cannot return a value. Reaching the closing brace also returns normally to the caller.