I read the following program code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int *p;
p= malloc(sizeof(int));
*p=42;
printf("Pointer p has address %p and points to %p\n",
(void*)&p, (void*)p);
free(p);
}
My question refers to the following part:
printf("Pointer p has address %p and points to %p\n", (void*)&p, (void*)p);
I don't understand what the (void*)
is doing. Is this a cast? What's the point of doing this?
What is the difference of the above to simply writing the following?
printf("Pointer p has address %p and points to %p\n", &p, p);