A void pointer is a special type of pointer. It can point to any data type, from an integer value or a float to a string of characters.
Void pointer limitation is that the pointed data cannot be referenced directly (the asterisk * operator cannot be used on them) since its length is always undetermined.
type casting or assignment must be used to turn the void pointer to a pointer of a concrete data type
int main()
{
int a=5,
double b=3.1415;
void *vp;
vp=&a;
printf(“\n a= %d”, *((int *)vp));
vp=&b;
printf(“\n a= %d”, *((double *)vp));
return 0;
}
Output:
a= 5
b= 3.141500
NULL POINTER
int *ip = NULL;
No comments:
Post a Comment