#include <stdio.h>
int main()
{
float f_value1 = 5.2f;
unsigned long ul_value1 = *((unsigned long *) &f_value1);
float f_value2 = *((float *) &ul_value1);
printf("\nf_value1 = %f, ul_value1 = %d, f_valu2 = %f", f_value1, ul_value1, f_value2);
unsigned long ul_value2 = (unsigned long) f_value1;
float f_value3 = (float) ul_value2;
printf("\n\nul_value2 = %d, f_valu3 = %f", ul_value2, f_value3);
printf("\n\n");
return 0;
}
输出:
f_value1 = 5.200000, ul_value1 = 1084647014, f_valu2 = 5.200000
ul_value2 = 5, f_valu3 = 5.000000