Demo code for using malloc and void pointer in c:
what is the mistake in this c code?
int *i = malloc(sizeof(int));
void *p = i;
we can't reference void pointer. second printf is wrong.
we can't reference int pointer, first printf is wrong.
no error but no output.
it gives error because, programmer is trying to reference void pointer. void pointers can be used to only store addresses,not for referencing because we don't what kind of data type is underlying data.
Back To Top