Type specifier for double in printf

Asked 1 years ago, Updated 1 years ago, 121 views

How should I write the format specifier for double in printf? Is it correct to use %f or %lf?

#include <stdio.h>
int main()
{
   double d =1.4;
   printf("%lf", d); //is this wrong?
}

c c++ format

2022-09-22 15:59

1 Answers

printf() can use either %f or %lf. printf is transmitted by converting float to double before receiving float There are two format specifiers for double instead of no format specifiers for float.

However, this applies only to outputs such as printf() and not to inputs such as scanf and fscanf. In the input, %f means to read float, %lf means to read %Lf, and %Lf means to read long double


2022-09-22 15:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.