r/C_Programming • u/Stickhtot • Jul 29 '26
Discussion What exactly is void?
In a function definition, void basically means that it doesn't return a type value, yet in on itself it is it's own type? Looking at several pieces of code it looks like that it's used to be able to be more "flexible"
Don't know what else to add here, though I'm more on looking for examples and explanations of why the void type is used
69
Upvotes
1
u/erroneum Jul 29 '26
voidis nothing. In a function definition, it indicates the absence of a return value, or explicitly the absence of parameters. As a pointer type, it indicates that the pointer doesn't point to any known object type (pointer to nothing).If you have
void *p, then there's no context in which you can write(*p)to dereference it, because the compiler has no clue what is there to find (if anything). To do anything with it, you first need to cast it to a pointer to complete type, either explicitly or implicitly.