Using printf function

后端 未结 5 1012
时光说笑
时光说笑 2021-01-22 13:01

I\'ve never bothered to look for printf as I started learning C++ without C. Now i want to use formatted output in some project. so I\'m looking for some references that can exp

5条回答
  •  耶瑟儿~
    2021-01-22 13:28

    When you write printf("%d", f); the type of f must be int. The code as you have written it invokes undefined behaviour. Taken from an answer to a similar question:

    in the documentation for fprintf (7.19.6.1/9) which also applies to printf, it explicitly states that if any argument is not the correct type for the format specifier - for an unmodified %d, that is int - then the behaviour is not defined.


    Why does it print zero?

    Maybe they ran out of nasal demons?

提交回复
热议问题