首页 > C Primer Plus 第三章打印浮点数(printf long double)

C Primer Plus 第三章打印浮点数(printf long double)

code showf_pt.c:

#include <stdio.h>

int main(void)
{
    float aboat = 32000.0;
    double abet = 2.14e9;
    long double dip = 5.32e5;
    printf("%f can be written %e\n", aboat, aboat);
    printf("%f can be written %e\n", abet, abet);
    printf("%f can be written %e\n", dip, dip);
    return 0;
}

output:

32000.000000 can be written 3.200000e+04
2140000000.000000 can be written 2.140000e+09
2140000000.000000 can be written 2.140000e+09

采用: /usr/loca/bin/gcc showf_pt.c -o /tmp/showf_pt 编译,
/usr/loca/bin/gcc --version:

gcc (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR     PURPOSE.

操作系统为Mac OSX。

后来改为: printf("%Lf can be written %Le\n", dip, dip);后编译正常,
同时请问如何打开编译警告?


double前加llong double前面加L-Wall打开警告。

【热门文章】
【热门文章】