值1.0e + 1的类型是什么 [英] What is the type of the value 1.0e+1

查看:97
本文介绍了值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,您需要了解转换说明符的正确用法.

  1. 要打印浮点,您需要使用%f
  2. 要打印 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 a float value or int 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.

  1. to print a float, you need to use %f
  2. 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 letter f or F, it has type float. If suffixed by the letter ``l or L, it has type long double.

这篇关于值1.0e + 1的类型是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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