Currently studying through how pointers work.
I understand void pointer is pointer with no associated data type, which allows it to hold address of any type and can be typecasted to any type.
In example code below, I see &ptrVar being casted to void*.
QUESTION: Why is the (void*) cast necessary? I removed the void* cast and seems like the program still outputs the same result.
Code:
#include <stdio.h>
int main()
{
int intVar = 10;
int *ptrVar = &intVar;
printf("ptrVar address: %p\n", (void*)&ptrVar); // Output the address
printf("value pointed to: %d\n", *ptrVar); // Value at the address pointed
return 0;
}