Mail Archives: djgpp/1998/05/31/10:43:00
> void main( void)
> {
> float f;
> f = 55 / 77;
> printf( "%f", f);
> }
> /* and please mail me YOUR results */
It does exactly what I expect: it prints 0. If you expect anything
else, you don't understand how C works. When you do this:
f = 55 / 77;
The compiler evaluates the 55/77 part first - the division of two
*integers*. Integer division returns an integer result (0). *Then*
it's converted to a floating point number (0.0) in order to store it.
If you want the compiler to divide floating point numbers, you have to
tell it to do that:
f = 55.0 / 77.0;
- Raw text -