student@ubuntu:~$
c 4/5 40 XP

Void Pointers

0%

Quick Reference

void * basics:

int x = 42;
void *vp = &x;           // Any pointer converts to void *
int *ip = (int *)vp;      // Must cast back to use
int val = *(int *)vp;     // Cast and dereference

Common standard library uses:

Function void * Usage
qsort Array pointer + comparator params
memcpy Source and destination pointers
memset Buffer pointer
calloc/malloc Return type
bsearch Array + key pointers

Common Pitfalls

  • Dereferencing without cast*vp won’t compile. Always cast: *(int *)vp.
  • Wrong cast – Casting to the wrong type reads garbage. If data is int, cast to int *, not double *.
  • Pointer arithmetic – Not allowed on void * in standard C. Cast to char * for byte-level arithmetic.
  • Type safety gone – void * bypasses type checking. The compiler can’t catch type mismatches — you must be careful.

Unlocks

Complete this skill to see what it unlocks.