L
liujiaping
The code is as follows:
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 float a = 1.0f;
8 cout << (int)a << endl;
9 cout << (int&)a << endl;
10 cout << boolalpha << ( (int)a == (int&)a ) << endl;
11 float b = 0.0f;
12 cout << (int)b << endl;
13 cout << (int&)b << endl;
14 cout << boolalpha << ( (int)b == (int&)b ) << endl;
15 return 0;
16 }
The program output is:
1
1065353216
false
0
0
true
I am wondering why line 9 prints 1065353216, while line 13 prints 0.
Can anybody explains this?
And what will happen if I convert a variable of type float to a
variable of type int&?
Any help is appreciated.
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 float a = 1.0f;
8 cout << (int)a << endl;
9 cout << (int&)a << endl;
10 cout << boolalpha << ( (int)a == (int&)a ) << endl;
11 float b = 0.0f;
12 cout << (int)b << endl;
13 cout << (int&)b << endl;
14 cout << boolalpha << ( (int)b == (int&)b ) << endl;
15 return 0;
16 }
The program output is:
1
1065353216
false
0
0
true
I am wondering why line 9 prints 1065353216, while line 13 prints 0.
Can anybody explains this?
And what will happen if I convert a variable of type float to a
variable of type int&?
Any help is appreciated.