Home

constvoidpointer

In C and C++, a const void pointer refers to a pointer to a const object of unspecified type. The type is written as const void* (or void const*). The const qualifier applies to the data pointed to, not to the pointer itself; thus you can assign a different address to the pointer, but you cannot modify the object through this pointer.

Because the pointed-to type is void, you cannot dereference the pointer directly to read or write the

Common use cases include generic APIs that operate on raw memory or buffers without committing to a

Pointer arithmetic on a void pointer is not defined in standard C; to move through bytes, you

Equivalence and related qualifiers: void const* is the same as const void*. A const qualifier on the

In practice, const void* conveys read-only, type-erased data, enabling generic interfaces while preserving type safety by

value.
To
access
the
data
you
must
cast
the
pointer
to
a
pointer
to
a
concrete
type,
such
as
const
int*
or
const
char*.
Casts
allow
reading
the
data,
but
you
must
respect
the
original
object's
const-ness.
specific
type,
such
as
interfaces
that
accept
a
const
void*
data
and
a
size.
For
example,
functions
like
memcpy
take
a
const
void*
source,
enabling
them
to
read
bytes
from
memory
without
knowing
the
exact
type.
cast
to
a
pointer
to
a
complete
type
(usually
char*
or
unsigned
char*)
and
perform
arithmetic
there.
pointer
itself
would
produce
void*
const,
which
means
the
pointer
cannot
be
reseated
but
the
pointed-to
data
may
be
modifiable
(if
not
also
const).
requiring
a
cast
back
to
a
concrete
type
when
accessing
the
underlying
object.