float2int

 

flaot转int时,会直接舍弃小数为,但是当把f所在的地址的数据当成int解析时,就是另外的情况了。

 

#include<iostream>
using namespace std;

int main()
{
    float f= 5.2;
    
    int *p = (int*)&f;
    cout << (int)f << endl;
    cout << *p << endl;

    return 0;
}

 

 

输出

5
1084647014

 

posted @ 2015-04-17 23:55  穆穆兔兔  阅读(487)  评论(0编辑  收藏  举报