Which conversion specifier must scanf() use to read a value into a variable of type double?
Correct answer D. %lf
Explanation
scanf receives a pointer, so it must know the exact target type: %f expects a float *, %lf a double * (and %Lf a long double *), while %ld is for long int. Using %f with a double writes only 4 bytes into an 8-byte variable, giving a wrong value. printf is different: float arguments are promoted to double, so %f and %lf both print a double.
Answer checked How we write and check questions
Discussion