什么是%f和%LF在C之间的区别? [英] What is the difference between %f and %lf in C?

查看:168
本文介绍了什么是%f和%LF在C之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一个C的例子,这两个参数在C的书,但作者没有详细说明什么,两者之间的区别是。我知道,%F 指定一个float应该取代其位置。我试图寻找这件事,但有一个很难试图找到该W符号。关于%LF

I saw these two parameters in a C example in a C book but the author didn't elaborate what the difference between the two are. I know that %f specifies that a float should take its place. I tried looking this up but had a hard time trying to find this w symbols. What about %lf?

推荐答案

有在的printf 家庭没有区别。在ISO C11标准(下面的所有引用来自C11),截面 7.21.6.1 fprintf函数,段落 / 7 状态,对于修改(我的粗体):

There is no difference in the printf family. The ISO C11 standard (all references below are from C11), section 7.21.6.1 The fprintf function, paragraph /7 states, for the l modifier (my bold):

指定后续的D,I,O,U,X,或X转换说明应用于long int或unsigned long int型参数;其后面的n转换说明适用于指向一个长整型参数;后续的c转换说明应用于wint_t参数;后续的s转换说明适用于一个指向wchar_t参数; 或有不影响后面的a,A,E,E,F,F,G,或G转换说明。

Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; that a following n conversion specifier applies to a pointer to a long int argument; that a following c conversion specifier applies to a wint_t argument; that a following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.

它并不需要修改˚F说明的原因是因为符的的表示,从段落 / 8 :

The reason it doesn't need to modify the f specifier is because that specifier already denotes a double, from paragraph /8 of that same section:

再presenting一个浮点数双参数转换为十进制表示在样式...

A double argument representing a floating-point number is converted to decimal notation in the style ...

这是与事实,继在函数原型的椭圆参数是受默认参数提升为每节 6.5.2.2函数调用,段落<$办C $ C> / 7

That has to do with the fact that arguments following the ellipse in the function prototype are subject to default argument promotions as per section 6.5.2.2 Function calls, paragraph /7:

...在一个函数原型声明符引起的参数类型转换到最后声明参数后,停止省略号。默认参数提升是在尾随参数执行。

... The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments.

由于的printf (和它的整个家庭)的家庭被声明为 INT的printf(为const char *限制格式,...); 用省略号表示法,该规则适用于这里。默认参数促销活动将在第 6.5.2.2函数调用,段落 / 6

Since printf (and it's entire family) family is declared as int printf(const char * restrict format, ...); with the ellipsis notation, that rule applies here. The default argument promotions are covered in section 6.5.2.2 Function calls, paragraph /6:

如果它表示所调用的函数的前pression有一个类型不包括样机,整数促销活动每个参数执行,和有float类型的参数都提升到两倍。这些被称为默认参数促销活动。

If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions.

对于 scanf函数系列,它要求使用的双击而非浮动。第 7.21.6.2 fscanf函数/ 11


For the scanf family, it mandates the use of a double rather than a float. Section 7.21.6.2 The fscanf function /11:

指定后续的D,I,O,U,X,X或n转换说明适用于有类型的指针参数传递给long int或unsigned long int类型; 其后面的a,A,E,E,F,F,G,或G转换符适用于有类型的指针参数为双; 或后续的c,S或[转换符适用于有类型的指针参数传递给wchar_t的。

Specifies that a following d, i, o, u, x, X, or n conversion specifier applies to an argument with type pointer to long int or unsigned long int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to an argument with type pointer to double; or that a following c, s, or [ conversion specifier applies to an argument with type pointer to wchar_t.

这会修改 / 12 该节中规定,对于第%F

This modifies the /12 paragraph of that section that states, for %f:

匹配任选签署浮点数,无穷大或NaN,其格式是相同的预期的的strtod函数的目标序列。相应参数应为指针浮动。

Matches an optionally signed floating-point number, infinity, or NaN, whose format is the same as expected for the subject sequence of the strtod function. The corresponding argument shall be a pointer to floating.

这篇关于什么是%f和%LF在C之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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