Possible Duplicate:
What is printf’s behaviour when printing an int as float?
int main()
{
int x=4;
int y=987634;
printf("%f %f",x,y);
}
On compiling this code i get an output as 0.000000 0.000000. Shouldn’t there be a type promotion of x and y to floating point numbers? Shouldn’t the O/P be 4.000000 and 987634.000000?
Can anyone help me with this. Thanx in Advance.
Conversions happen to arguments to functions with a prototype which includes the specific parameters. The prototype for
printf()does not include the specific parameters after the first oneso, no arguments after the 1st one get automatically converted except as defined by “default argument conversions” (basically any integer type with a rank lower than
inttointand any floating-point type with a rank lower thandoubletodouble(thank you, Pascal Cuoq)). You need to convert them explicitly yourself with a cast operationOhhh … and you really, really, really should include the header that has the prototype in question (under penalty of Undefined Behaviour)