值1.0e + 1的类型是什么 [英] What is the type of the value 1.0e+1
问题描述
1.0e + 1
是否返回 float
值或 int
值?
当我打印 1.0e + 1
时,它会给出 10
,但是当我执行 sizeof(1.0e + 1)
时,它会给我 10> 8
.
1.0e + 1
是否返回float
值或int
值?
回答:无.按照它的写法,它表示一个 double
.
Nitpick:让我们使用术语"代表"代替"返回
我觉得你很困惑.IHMO,您需要了解转换说明符的正确用法.
- 要打印浮点,您需要使用
%f
- 要打印
sizeof
输出,您需要使用%zu
也就是说, printing 1.0e + 1
意味着打印 value ,而 sizeof(1.0e + 1)
本质上是 sizeof(double)
,因为浮点文字默认情况下是 double
.
C11
标准相关的第6.4.4.2章不带后缀的浮点常量的类型为
double
.如果以字母f
或F
结尾,则其类型为float
.如果以字母``l或L
为后缀,则其类型为long double
.
Does 1.0e+1
return a float
value or int
value?
When I print 1.0e+1
it gives 10
but when I do sizeof(1.0e+1)
it gives me 8
.
Does
1.0e+1
return afloat
value orint
value?
Ans: None. As is it written, it represents a double
.
Nitpick: Let's use the term represent instead of return
I think you're confused. IHMO, you need to know about the proper usage of the conversion specifiers.
- to print a float, you need to use
%f
- to print a
sizeof
output, you need to use%zu
That said, printing 1.0e+1
means printing the value whereas, sizeof(1.0e+1)
is essentially sizeof(double)
, because, floating point literal is by default a double
.
Related, from C11
standard, chapter §6.4.4.2
An unsuffixed floating constant has type
double
. If suffixed by the letterf
orF
, it has typefloat
. If suffixed by the letter ``l orL
, it has typelong double
.
这篇关于值1.0e + 1的类型是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!