posted 23 years ago
Hello!
Have you tried executing any of these little snipplets? Isn't it strange that the result of
float f = 1/3;
is 0.0? The reason for this is also the reason why
int i = 1/3;
executes.
Actually, both 1 and 3 are integers. Right? And if you divide one int with another, the answer, too, will come in the shape of an int. In ordinary math, 1/3 yields 0.33333. But as an int cannot store the decimal part, the result will be 0. This result can then be stored in an int, in which case the int's value will be 0. The result can also be stored in a float, in which case the float's value will be 0.0...
I recommend reading RHE, chapter 2, "The Arithmetic Operators".
Hope this helps!
//Kaspar