Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.