0

How can I know which type(int, double, float etc..) is currently holding of void pointer? Suppose

void *p;

int x=10;

p=&x;

printf("%s",type_of_void_pointer(p));

double d=1.5;

p=&d;

printf("%s",type_of_void_pointer(p));

The first printf should print "int" whereas second should print "double" Is there any way to write type_of_void pointer function?

rh939
  • 55
  • 4

1 Answers1

1

You can't know the type from the content in anyway. From the void* itself it is no way possible to know this. It is all address. Even if you look into the content it is impossible to know the type of it.

All you know here is the address and that's it. You can even cast it to different type and interpret it different way.

user2736738
  • 30,591
  • 5
  • 42
  • 56