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

后端 未结 5 2001
伪装坚强ぢ
伪装坚强ぢ 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:36

    scanf needs to know the size of the data being pointed at by &d to fill it properly, whereas variadic functions promote floats to doubles (not entirely sure why), so printf is always getting a double.

提交回复
热议问题