Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The void keyword in C designates an incomplete type that cannot be instantiated or completed. It explicitly represents the absence of a value, the absence of parameters, or, when combined with a pointer declarator, a memory address of an unspecified data type. Because it lacks a defined size and memory layout, the compiler prevents the creation of variables of type void.

Function Return Type

When used as a function return type, void instructs the compiler that the function does not yield a value to the caller. Any attempt to evaluate the function call as an expression or extract a return value results in a compilation error.
void function_name(int param);

Function Parameter List

In C, placing void inside a function’s parameter list strictly enforces that the function accepts exactly zero arguments. This is a critical semantic distinction from an empty parameter list (), which in older C standards denotes an unspecified number of arguments.
int function_name(void);

Generic Pointers (void *)

A pointer to void represents a raw memory address without associated type semantics. Because the compiler does not know the size of the underlying data or how to interpret its bit pattern, a void * cannot be directly dereferenced, nor can it be used in standard pointer arithmetic (as the stride length is unknown). Unlike C++, C allows a void * to be implicitly converted to and from any other object pointer type without an explicit cast. To access the underlying memory, the void * must either be assigned to a pointer of a complete type (relying on implicit conversion) or explicitly cast inline prior to dereferencing. Forcing an explicit cast during standard assignment is unnecessary and considered an anti-pattern in C.
int val = 0;
void *ptr = &val;

/* Implicit conversion to a typed pointer (idiomatic C) */
int *int_ptr = ptr; 

/* Explicit cast required only for direct inline dereference */
*(int *)ptr = 5;

Void Cast

An expression can be explicitly cast to void. This operation evaluates the expression for its side effects but intentionally discards the resulting value. It is a syntactic mechanism to signal to the compiler that a value is deliberately ignored, often suppressing unused-result warnings.
(void)function_returning_value();
Master C with Deep Grasping Methodology!Learn More