1

Possible Duplicate:
How is conversion of float/double to int handled in printf?

main()
{
    printf("%f",1);
}

The output I expected was 1.000000,i.e the int 1 being upcasted to double 1.000000 , but it gave 0.000000. Why is it so ?

Community
  • 1
  • 1
cirronimbo
  • 909
  • 9
  • 19

1 Answers1

4

When a non-matching argument is provided to the formatting directive (in this case an int to a %f) the resulting behavior is undefined.

This question, or some variation of it, comes up periodically, see What is printf's behaviour when printing an int as float? and problem with printf function? for examples/more information.

Community
  • 1
  • 1
Levon
  • 138,105
  • 33
  • 200
  • 191