code one is:
int a = 0x42500000;
float *f = (float *)&a;
printf("%f", *f); //output 52.00000
code two is:
int a = 0x42500000;
float f = (float)a;
printf("%f", f); //output 0.00000
why code two output 0.00000,who can tell me why?
First snippet interprets the contents of the memory location of
aas if it were float, without casting. Unless you really know what you are doing, you don’t want to do that, it’s almost always a mistake.The second snippet casts the value of
ato float, which should give you the same value as the int. It really does do that. Your code gives me1112539136.000000. What compiler are you using and getting0there?