How can printf use f for type double, if scanf requires lf?
Someone told me it was wrong to use %lf with printf. How can printf use %f for type double, if scanf requires %lf?
It's true that printf's %f specifier works with both float and double arguments Due to the ``default argument promotions'' (which apply in variable-length argument lists values of type float are promoted to double, and printf therefore sees only doubles. (printf does accept %Lf, for long double.) scanf, on the other hand, accepts pointers, and no such promotions apply. Storing into a float (via a pointer) is very different from storing into a double, so scanf distinguishes between %f and %lf.
Here is a table listing the argument types expected by printf and scanf for the various format specifiers:
[TABLE GOES HERE]
(Strictly speaking, %lf is undefined under printf, though many systems probably accept it. To be portable, always use %f.)
2015-11-06, 503👍, 0💬
In C#, what is a weak reference? Generally, when you talk about a reference to an object in .NET (an...
How To Define a Sub Function? - Oracle DBA FAQ - Creating Your Own PL/SQL Procedures and Functions A...
How does multi-threading take place on a computer with a single CPU? The operating system's task sch...
How do you estimate maintenance project and change requests?
What is test metrics? Test metrics accomplish in analyzing the current level of maturity in testing ...