C Void Pointers

Work with generic untyped pointers for polymorphous data manipulation.

A void* is a generic pointer that can point to any data type without type-casting. It is the foundation of standard generic library routines like qsort() and memcpy().

Key Takeaways: C Void Pointers

Mastering C Void Pointers helps you write clean and reliable C code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

C Void Pointers Code Example

C
#include <stdio.h>

void printValue(void* ptr, char type) {
    if (type == 'i') printf("Integer: %d\n", *(int*)ptr);
    if (type == 'f') printf("Float: %.2f\n", *(float*)ptr);
}

int main() {
    int num = 100;
    printValue(&num, 'i');
    return 0;
}
Output
Integer: 100
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services