一个float变量的空间实体,被一个整形指针指向,当该指针间访时,float变量的空间实体便现出整形实体的面相,于是34.5这个浮点数按二进制补码来理解,得出的结果变得怪异了:
34.5=100010.1
(2)
=1.000101*2
5(2)
=0,10000100,00010100000000000000000
结果变成
2
30+2
25+2
19+2
17=1107951616
原来的程序为
#include<iostream>
using namespace std;
int main()
{ float f= 34.5;
int *ip= reinterpret_cast<int*>(&f);
cout<<"float address: "<<&f<<"=>"<<f<<endl;
cout<<" int address: "<<ip<<"=>"<<*ip<<endl;
*ip=100;
cout<<" int: "<<*ip<<endl;
cout<<" float: "<<f<<endl;
}
上面的34.5=100010.1
(2)
=1.000101*2
5(2)
=0,10000100,00010100000000000000000我看不太懂 希望能得到你们的指点