为什么scanf()的需要"%LF"双打,当printf()的是好的只有"%F"? [英] Why does scanf() need "%lf" for doubles, when printf() is okay with just "%f"?

查看:120
本文介绍了为什么scanf()的需要"%LF"双打,当printf()的是好的只有"%F"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么说 scanf()的需要%LF 双击,当的printf()可以使用时,%F ,无论其参数是否是双击浮动 <? / p>

举例code:

 双D;
scanf函数(%LF,和D);
的printf(%F,D);


解决方案

由于C将促进花车双打对于采用可变参数的函数。指针不松口任何东西,所以你应该使用%LF LG%%乐(或%LA 在C99)在双打阅读。

Why is it that scanf() needs the l in "%lf" when reading a double, when printf() can use "%f" regardless of whether its argument is a double or a float?

Example code:

double d;
scanf("%lf", &d);
printf("%f", d);

解决方案

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.

这篇关于为什么scanf()的需要&QUOT;%LF&QUOT;双打,当printf()的是好的只有&QUOT;%F&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆