Understanding implicit conversions for printf

前端 未结 2 1671
终归单人心
终归单人心 2021-01-25 04:44

The C99 Standard differentiate between implicit and explicit type conversions (6.3 Conversions). I guess, but could not found, that implicit casts are performed, when the target

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-25 05:25

    printf("INT_MIN as double (or float?): %e\n", a);
    

    Above line has problem You can not use %e to print ints. The behavior is undefined.

    You should use

    printf("INT_MIN as double (or float?): %e\n", (double)a);
    

    or

    double t = a;
    printf("INT_MIN as double (or float?): %e\n", t);
    

    Related post: This post explains how using incorrect print specifiers in printf can lead to UB.

提交回复
热议问题