1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Which printf conversion specifier correctly prints a…

Added 30 Nov -0001

Which printf conversion specifier correctly prints a double variable in C?

  1. %c
  2. %s
  3. %f Correct answer
  4. %d

Correct answer

C. %f

12 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs