c++ - 双倍作为实数的默认数据类型

标签 c++ type-conversion

当任何实数如 10.10 作为参数传递给函数时,为什么它总是假定为 double 而不是 float ?

编辑:我知道如果我想让它 float ,我总是可以使用 10.10f。
但我想知道的是,是否有任何“具体/精确”的理由将其假定为 double ?

最佳答案

When any real number say 10.10 is passed as argument to function, why is it always assumed to be double and not float ?

因为文字 10.10 的类型是 double

如果您总是将 double 传递给函数,则参数“始终假定为 double”。

But what I want to know is that is there any "specific/precise" reason why is it assumed to be double ?

因为这是双文字的语法。

如果你看一下 this page, describing the syntax of floating point literals ,你会发现

suffix, if present, is one of f, F, l, or L. The suffix determines the type of the floating-point literal:

  • (no suffix) defines double
  • f F defines float
  • l L defines long double

强调我的。

关于c++ - 双倍作为实数的默认数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38374133/

相关文章:

c++ - 在 C++ 中有没有办法转到文本文件中的特定行?

c++ - 包含所有必要的#include 语句的单个头文件

c++ - 使用 C++0x : call to deleted constructor of 时的 clang++ 错误消息

java - Java中转换的模糊概念

java - 有符号字符到字节

interface - 我可以键入断言一部分接口(interface)值吗?

c++ - 在 C++ 中使用模板获取和设置不同数据类型的值

c++ - 什么是 freq_table[field_pm_value] = map<string, int>();方法?

c++ - 双向链表插入方法实现-搜索什么节点

c++ - Clang 和 GCC 不同意使用转换运算符直接初始化的合法性