`void` — C Keyword

`void` — C Keyword

The void keyword in C: represents the absence of type.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

void (C)

Represents the absence of type. Used as a function return type when no value is returned, and as void* for an untyped pointer.

Syntax

void function-name(params);
void* ptr;

Example

#include <stdio.h>
#include <stdlib.h>

void greet(const char* name) {
    printf("Hello, %s!\n", name);
}

int main(void) {
    greet("World");

    /* void* — generic pointer */
    void* raw = malloc(4 * sizeof(int));
    int* arr  = (int*)raw;
    arr[0] = 42;
    printf("%d\n", arr[0]);  /* 42 */
    free(raw);
    return 0;
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}