On this page
void
Prev: _Noreturn | Up: builtins | Next: char
Rel: Pointers & Pointer Arithmetic
Ref: cppreference — void
Tags: #public #prog #c #builtins #tier/core
Availability
Built-in (Built-in Type) — requires no #include header.
Syntax & Overview
void fn(void); | void *ptr;
Represents the absence of a value (empty return or parameter list) or an untyped generic object pointer (void *).
Notes & Pitfalls
- Always write
int f(void)for zero-argument functions in C (pre-C23int f()meant unspecified arguments, disabling argument-count checking!). void *converts implicitly to/from any object pointer (no cast needed onmalloc()in C).
Example
#include <assert.h>
static int answer(void) { return 42; }
int main(void) {
int x = answer();
void *vp = &x;
int *ip = vp;
assert(*ip == 42);
}
Linked from
Related notes
- tuts/c/builtins/_Noreturn Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/char Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins Linked here; links to this page; shared tags: #builtins, #c, #prog
- tuts/c/pointers_and_memory/pointers_and_pointer_arithmetic Linked here; shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__func__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__LINE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__STDC_VERSION__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Alignof shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Atomic shared tags: #builtins, #c, #prog, #tier