On Floats and Integers

Previous | Next | Home

Just look at the following code snippet and try to make out why we get the output that we get.

The Program

#include <iostream.h>

void main()
{
	int i = 10;
	float *pf = (float *)&i;

	cout<<"i : "<<i<<endl;
	cout<<"*pf : "<<*pf<<endl;
}

The Output

i : 10
*pf : 1.4013e-044

That is to say, the number 10 when shown as a float gives what one would obtain by dividing the number 1.4013 by 10 raised to the power of 44! The question is - why? :-). To know the answer,
click here.

Previous | Next | Home 1