A void pointer (void *) in C and C++ is a pointer that points to a memory location with no specified type.
A void pointer (void*
) in c and c++ is a pointer that points to a memory location with no specified type. A void *
is typically used to exchange pointers, where some called function may not care about the type of the argument that it receives — for example, functions which operate on raw memory (such as realloc
and bzero
) and functions which pass along the pointer without needing to access it (for example, GTK+ callbacks).
In C, the use of void *
is considered idiomatic as long as no undefined operations (such as dereferencing it or performing pointer arithmetic on it) are taken on the pointer, as C lacks type-safe generics. Unless working with C libraries, C++ users should avoid void *
and use templates instead, as compilers can detect usages of templates that are not type-safe.
Note that in standard C, you cannot perform arithmetic on a void *
; the GNU C Compiler allows such arithmetic as a (non-portable) extension.