c - printf 和 long double

标签 c gcc printf long-double

我在 Windows 上将最新的 gcc 与 Netbeans 一起使用。为什么 long double 不起作用? printf 说明符 %lf 是否错误?

代码:

#include <stdio.h>

int main(void)
{
    float aboat = 32000.0;
    double abet = 5.32e-5;
    long double dip = 5.32e-5;

    printf("%f can be written %e\n", aboat, aboat);
    printf("%f can be written %e\n", abet, abet);
    printf("%lf can be written %le\n", dip, dip);

    return 0;
}

输出:

32000.000000 can be written 3.200000e+004
0.000053 can be written 5.320000e-005
-1950228512509697500000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000.000000
can be written 2.725000e+002
Press [Enter] to close the terminal ...

最佳答案

是的——对于long double,您需要使用%Lf(即大写的“L”)。

关于c - printf 和 long double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53489346/

相关文章:

c++ - 是否保证堆分配的 block 地址不会(隐式地)改变?

c++ - 如何在没有编译器警告的情况下进行可移植的 64 位算术

multidimensional-array - F# 打印出一个二维字符串数组

c - 格式字符串周围的 `TEXT` 在 "printf"中是什么意思

c - printf 语句是如何解释的?

java - 在 Java 中从 JNI 设置值 : JNI java. lang.NoSuchFieldError

c - 为什么我可以覆盖一 block 分配了 0 个空间的内存?

C:在文件中搜索字符串

c - C程序中的ASM代码导致段错误

c - 如果在 C 中使用 malloc((size_t)NULL) 会发生什么