sizeof(3.0) 和 sizeof(3.0f) 有什么区别
我期待他们两个给出相同的结果(sizeof float)..但它不同。
在32位机器上,gcc编译器, sizeof(3.0f) =>4 sizeof(3.0) => 8
为什么会这样?
最佳答案
因为 3.0 是 double 的。参见 C syntax Floating point types .
Floating-point constants may be written in decimal notation, e.g. 1.23. Scientific notation may be used by adding e or E followed by a decimal exponent, e.g. 1.23e2 (which has the value 123). Either a decimal point or an exponent is required (otherwise, the number is an integer constant). C99 introduced hexadecimal floating-point constants, which follow similar rules except that they must be prefixed by 0x and use p to specify a hexadecimal exponent. Both decimal and hexadecimal floating-point constants may be suffixed by f or F to indicate a constant of type float, by l or L to indicate type long double, or left unsuffixed for a double constant.
关于c - sizeof float (3.0) 与 (3.0f),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1355379/