c - sizeof float (3.0) 与 (3.0f)

标签 c sizeof

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/

相关文章:

c++ - 如何计算与服务器的 SYN/ESTABLISHED 连接?

C语言for循环创建线程

c - 意想不到的 *, 意想不到的 (

c - 首先通过套接字发送我要发送的文件的大小

c++ - sizeof 运算符生成的数据类型

c++ - C++模板参数sizeof返回错误的结果

c - Google Protocol Buffers 是否有良好的 C 实现

c - 以下代码是否违反严格别名?

c++ - 为什么 sizeof(argv)/sizeof(argv[0]) 给我 C++ 中数组的大小?

c - 可变长度数组上 sizeof 的行为(仅限 C)