Why does scanf() need “%lf” for doubles, when printf() is okay with just “%f”?

后端 未结 5 2040
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 06:03

Why is it that scanf() needs the l in \"%lf\" when reading a double, when printf() can use \"%f

5条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 06:48

    Using either a float or a double value in a C expression will result in a value that is a double anyway, so printf can't tell the difference. Whereas a pointer to a double has to be explicitly signalled to scanf as distinct from a pointer to float, because what the pointer points to is what matters.

提交回复
热议问题