Re: Shouldn't be the output of program be 1.000000 ?
It would have been had your division resulted in a float value rather than an int. Since you tried to print an int with a %f format specification, the result was undefined behavior.
More details:
There are two problems, related though:
You are getting an integer result from your division, but
trying format for a float value using %f
(Your question seems to imply you are aware of this) Integer
division results in an integer which is why the %f format
specifier isn't appropriate. When the format specifier and the
argument don't match the behavior is undefined.
To avoid an integer result, try:
9.0 / 5 or 9 / 5.0 or even 9.0 / 5.0
to get the result you were expecting and then the %f specifier will be appropriate and work as expected.
Note that when you are doing integer division, the result will be another integer. If, however, at least one of the operands is a float, the other operand will be promoted to a float too and the division will result in a float value.
With integer division you get truncation, which means the fractional part of the result is thrown away.