I have a void
pointer pointing to a memory address. Then, I do
int
pointer = thevoid
pointerfloat
pointer = thevoid
pointer
and then, dereference them go get the values.
{
int x = 25;
void *p = &x;
int *pi = p;
float *pf = p;
double *pd = p;
printf("x: n%d\n", x);
printf("*p: %d\n", *(int *)p);
printf("*pi: %d\n", *pi);
printf("*pf: %f\n", *pf);
printf("*pd: %f\n", *pd);
return 0;
}
The output of dereferencing pi
(int
pointer) is 25.
However the output of dereferencing pf
(float
pointer) is 0.000.
Also dereferncing pd
(double
pointer) outputs a negative fraction that keeps
changing?
Why is this and is it related to endianness(my CPU is little endian)?
int
,float
, anddouble
have can - and in the case offloat
anddouble
do - have different sizes, which more than implies a different internal representation. – Cadge