LearnFrenzy
Sign in Take a free test

Floating Point Issues · Floating Point MCQ · Question 6

scanf: %f vs %lf for float and double Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

Which pair is correct?

  • A printf %lf for double only; scanf %f for both
  • B %f is always wrong for double
  • C printf %f works for float and double; scanf needs %f for float and %lf for double Correct
  • D Both functions treat %f and %lf the same
Correct Answer: Option C

Variadic arguments promote float to double, so printf only ever receives doubles and %f serves both (%lf is also accepted). scanf receives pointers, and a double * must be read with %lf.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links