Skip to content

Instantly share code, notes, and snippets.

@joegasewicz
Created November 23, 2022 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joegasewicz/5c7c9b29aa840c8318ac19861ed4fc24 to your computer and use it in GitHub Desktop.
Save joegasewicz/5c7c9b29aa840c8318ac19861ed4fc24 to your computer and use it in GitHub Desktop.
Void Pointers
/* ====================================================================== */
/* Void Pointers*/
/* ====================================================================== */
// void* absence of a type means you are able to store any type
// - Often used as a return type or a parameter type of functions
// - You must cast it to a type when you dereference it
int i = 10;
float f = 2.34;
char ch = 'k';
void *vptr = NULL;
vptr = &i;
printf("Value of i = %d\n", *(int*)vptr);
vptr = &f;
printf("Value of f = %.2f\n", *(float*)vptr);
vptr = &ch;
printf("Value of ch = %c\n\n\n", *(char*)vptr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment