当任何实数如 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/