Which printf conversion specifier correctly prints a double variable in C?
Correct answer
C. %f
12 views
C. %f
12 views
The %f specifier expects a floating-point argument and prints it in decimal notation, defaulting to six digits after the point. Using %d with a double is undefined behaviour, because the variadic call passes the value in a floating-point register while %d reads an integer register. Modern compilers warn about this mismatch, and %lf is accepted in printf for symmetry with scanf but behaves identically to %f.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.