By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

conversion from float to int&

P: n/a
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.

Aug 13 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.