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

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

    Because otherwise scanf will think you are passing a pointer to a float which is a smaller size than a double, and it will return an incorrect value.

提交回复
热议问题