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

后端 未结 5 2012
伪装坚强ぢ
伪装坚强ぢ 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 C will promote floats to doubles for functions that take variable arguments. Pointers aren't promoted to anything, so you should be using %lf, %lg or %le (or %la in C99) to read in doubles.

提交回复
热议问题