Because void and void* have different meanings. You use the one that matches what you are trying to define.
Why the dereference operator is used with the void keyword while declaring a void pointer?

Debojit Acharjee
455
Reputation points
Why the indirection/dereference operator (*) is used with the "void" keyword while declaring a void pointer? But in case of any other type of pointers the operator can be used with the pointer name.
#include <stdio.h>
int main()
{
int a = 1;
int *a2_ptr = &a;
void* a_ptr = &a;
printf("Value of 'a' from void pointer is %d and int pointer is %d\n", *(int*)a_ptr, *a2_ptr); // Dereferencing of void pointer using type casting
return 0;
}
In the above program, the integer pointer "a2_ptr" is declared using the * operator with the pointer name but in case of the void pointer, why the operator is used with the "void: keyword?
Developer technologies | C++
3,977 questions
Developer technologies | Visual Studio | Other
5,455 questions
Accepted answer
1 additional answer
Sort by: Most helpful
-
Bruce (SqlWork.com) 78,086 Reputation points Volunteer Moderator
2023-07-26T15:43:23.9133333+00:00 The void* is used to declare an address pointer, where the type that the address points to is unknown.