#include
int main(void)
{
double c;
scanf(\"%f\", &c);
printf(\"%f\", c);
}
This is an exerpt from a program
You need to use "%lf"
for double.
This is the warning from clang compiler.
warning: format specifies type 'float *' but the argument has type 'double *' [-Wformat] scanf("%f", &c);
Here is the scanf reference. It's format is %[*][width][length]specifier
. The specifier for 'floating point number' is f
. So we use %f
to read float x
. To read double x
, we need to specify the length as l
. Combined the format is %lf
.