Originally Posted by
eXeCuTeR
Doesn't (int *)&n (assuming n is an int) supposed to return a pointer to a pointer (**)?
I mean, you are casting the address of n into an int pointer - or what exactly happens if I cast something into a pointer?
&n is float*, the address of a float variable, not a pointer to pointer.
Consequently, float* is not int*, therefore I use a cast to turn that float* into int*.
Casting turns the type on the right side into the type on the left side. It does not take the address.
Look at this:
Code:
#include <stdio.h>
int main()
{
float f = 1.0f;
int* n;
memcpy(&n, &f, sizeof(int*));
printf("%p\n", n);
n = (int*)&f;
printf("%p\n", n);
printf("%i\n", *n);
printf("%f\n", *(float*)n);
return 0;
}
The output is:
3F800000
0012FF60
1065353216
1.000000