Basic and Advance C Question:
Download Questions PDF

How can f be used for both float and double arguments in printf? Are not they different types?

Answer:

In the variable-length part of a variable-length argument list, the ``default argument promotions'' apply: types char and short int are promoted to int, and float is promoted to double. (These are the same promotions that apply to function calls without a prototype in scope, also known as ``old style'' function calls. Therefore, printf's %f format always sees a double. (Similarly, %c always sees an int, as does %hd.)

Download C Programming Interview Questions And Answers PDF

Previous QuestionNext Question
I had a frustrating problem which turned out to be caused by the lineI heard that you have to include stdio.h before calling printf. Why?