Which of the following format specifiers can be used to read floating type…
2022
Which of the following format specifiers can be used to read floating type values, in C programming?
- A.
%e
- B.
%f
- C.
%g
- D.
All options are correct
Attempted by 1730 students.
Show answer & explanation
Correct answer: D
Concept: A C format specifier used with scanf() controls how an input token is parsed into a variable, not how the value is later printed. For floating-point input, %e, %f, and %g all invoke the same underlying conversion routine, so each one independently is capable of reading a decimal- or exponential-form number typed by the user.
%e reads a floating value and is normally paired with exponential (scientific) notation for output -- but for input it behaves the same as the other two.
%f reads a floating value and is normally paired with plain decimal notation for output -- again, identical behaviour on input.
%g reads a floating value and automatically chooses decimal or exponential form for output -- its input behaviour matches %e and %f as well.
Since the question asks which specifier(s) CAN be used to read a floating-point value, and %e, %f, and %g are each independently valid for that purpose, the complete and correct answer is that all of them work -- not any single one alone.