As far as I know about data types in C/C++, while declaring a variable, we need to declare its data type, which tells the compiler to reserve the number of bytes in the memo
Assume that this code compiles without error (as you would like):
int a;
int b = 42;
void * d = &b;
a = *d;
What should be the value of a?
Now with this one:
int a;
float b = 42.0;
void * d = &b;
a = *d;
What do you expect in a?
Actually the type specifies how should the pointed area be interpreted. You should specify int *
in the first example and float *
in the second one, instead of void *
.