When I compile and run the following snippet of code, the output is 0.000000.
#include <stdio.h>
int main(void)
{
double a = 1.4;
printf("%lf", a);
return 0;
}
When I compile and run this snippet of code, the output is 1.400000, as I expected it to be for the first snippet.
#include <stdio.h>
int main(void)
{
double a = 1.4;
printf("%f", a);
return 0;
}
Why is this the case? %lf is a format specifier for doubles so shouldn't the first snippet have the same output as the second?
Someone asked a similar question (Correct format specifier for double in printf) but according to the top answers, the two snippets should produce identical output as "the l is specified as having no effect if followed by the f conversion specifier (among others)" (quoted from first answer).
I'm using code-blocks as an IDE and I made the gcc compiler follow the 1999 standard for C. The possible duplicate says my code should work according to the C99 standard, which my compiler follows, but my code doesn't work. The answer in the duplicate therefore doesn't solve my problem.