Example code for using void pointer in c:
what is the mistake in this c code?
int *i = malloc(10);
void *p = i;
we have to typecast malloc to (int *) else it gives error.
we can't assign integer pointer to void pointer.
we can assign integer pointer to void pointer, but we have to typecast it while assigning, else it gives compile time error.
void pointers are generic pointers in c. we can assign any pointer to void *. so this statement is legal.
Back To Top