I am getting output 0.23
from second printf
. But typecasting gives required output. If I am not using type casting previous value is printed.
Compiler
The problem is a combination of two factors:
The first is that for vararg functions like printf
, the compiler will not do any implicit conversions of the arguments. So the 0
in the argument list is an integer constant (of type int
).
The second factor is the mismatching format specifier. The printf
function doesn't know anything about the arguments being passed, except what is specified in the format string. Mismatching format and argument type leads to undefined behavior. And since the "%f"
specifier make printf
expect a value of type double
, and you have given an int
value, you have such a mismatch.