The void data type, in simple words, means ‘nothing’. This data type either explicitly declares a function that doesn’t return any value or creates generic pointers. There are different functions available in C programming that do not return any value. In short, we can say that those functions return void. A function with no value to return has the return type void. In C, there are functions that do not accept any parameter. Such functions can accept void. A pointer of type void * represents the address of an object, but not its type. For example, void *malloc(size_t size);
, which is a memory allocation function, returns a pointer to void which can be typecasted to any data type. The uses of void data type with function and pointer are shown below via declarations:
void add() {...} /* function with no return type, i.e. void */
void *vptr; /* vptr is a void printer variable that can hold any type of pointer */