常量的默认类型如12.5,1e-3,float还是double? [英] default type for constants like 12.5, 1e-3, float or double ?

查看:462
本文介绍了常量的默认类型如12.5,1e-3,float还是double?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



K& R表示浮点常数包含小数点

(123.4)或指数(1e-2)或两者兼有;他们的类型是双;除非

后缀。后缀f或F表示浮点常数; l或L

表示长双。


问题是这些常量默认为双倍,除非后缀为

with f或F?


提前致谢。


新手。

解决方案

Greenhorn写道:


K& R说浮点常数包含小数点
(123.4)或指数(1e-2)或两者兼而有之;他们的类型是双;除非
后缀。后缀f或F表示浮点常数; l或L
表示长双。

问题是这些常量默认为双,除非后缀
与f或F?




是的,默认情况下,未固定的浮点常数是双倍




float k = 12.4;


上面的变量k会被强制加倍吗?


greenhorn


blockquote>
blockquote> Greenhorn写道:

float k = 12.4;

上面的变量''k''会被强制类型强制加倍?

greenhorn



不,k仍然是声明的浮动。

双值12.4将被转换为浮点数,然后

分配给k。


Hi,
K&R says that "floating point constants contain a decimal point
(123.4) or an exponent (1e-2) or both; their type is double; unless
suffixed. The suffixes f or F indicate a float constant; l or L
indicate a long double."

the question is are these constants double by default unless suffixed
with f or F ?

Thanks in advance.

greenhorn.

解决方案

Greenhorn wrote:

Hi,
K&R says that "floating point constants contain a decimal point
(123.4) or an exponent (1e-2) or both; their type is double; unless
suffixed. The suffixes f or F indicate a float constant; l or L
indicate a long double."

the question is are these constants double by default unless suffixed
with f or F ?



Yes, unsuffixed floating point constants are double by default



float k = 12.4;

will the above variable ''k'' be type coerced to double ?

greenhorn


Greenhorn wrote:

float k = 12.4;

will the above variable ''k'' be type coerced to double ?

greenhorn


No, k remains a float as declared.
The double value 12.4 will be casted to a float, then
assigned to k.


这篇关于常量的默认类型如12.5,1e-3,float还是double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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