#include <stdio.h>
#include <math.h>
int main(void){
printf("%lf\n", pow(1.0, 2.0));
printf("%f\n", pow(1.0, 2.0));
return 0;
}
First printf() gives output 0.000000 but second printf() gives output 1.000000. Why?
Using Codeblocks on Windows 7 64 bit.
Using gcc command to compile give me an .exe that outputs 1.000000 for both statements.
If I compile pressing F9 on Codeblocks, I get 0.000000 for the first statement and 1.000000 for the second.
Finally, if I remove #include <stdio.h> from source code in Codeblocks, all give me 1.000000 (no warnings or errors).
Your code should print the same value for both lines on a C99 or C11 compiler. All
floatarguments toprintfare always converted todouble, and%lfand%fboth do the same thing (print adouble).In the C89 standard, the
%lfspecifier is undefined behavior anddoubles should only be printed with%f. So perhaps you're using an old compiler which doesn't support the C99 standard.Relevant sections of the standards regarding
%lf:C99, 7.19.6.1/7:
C89, 4.9.6.1: