isrobert
“float a = 5.5; printf("%d\n",a); 结果应该是0,所以答案如果是1085276160也就只能解释为地址了”
--- 这又涉及到另外一个问题了,即:“float在入栈时,自动转化为double”,然后你又用"%d"只取了这8字节double中4字节,……
你可以这样试验#include <iostream>using namespace std;
int main(){ float a = 5.5f;
// 方法一 union X { float f; int d; } x; x.f = a; cout << x.d << endl;
// 方法二 cout << *(int*)&a << endl;
方法三 cout << (int&)a << endl;}
Copyright © isrobert