This is a trivial program in Turbo C 2.01. It is intended to show that C can do arithmetic with mixed data types, and what the results are:
#include <stdio.h>
void main(void)
{
int num1 = 5;
float num2 = 2;
int num3;
num3 = num1 / num2;
printf( "%f\n", num3);
}
I would expect it to print 2, or maybe 3, but it prints 0.0000, as if the division failed. It does not generate any warnings or errors when compiled.
This is not what the book says it will produce, and the book was written for this version of Turbo C.
If I declare num3 as a float, it prints out 2.50000, which is what I would expect.
Did I do something wrong, or am I misunderstanding something?
Environment is Borland Turbo C 2.01 on Windows XP Pro SP3.