Why is it that scanf() needs the l in ‘%lf‘ when reading a double, when printf() can use ‘%f‘ regardless of whether its argument is a double or a float?
Example code:
double d; scanf('%lf', &d); printf('%f', d);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because C will promote floats to doubles for functions that take variable arguments. Pointers aren’t promoted to anything, so you should be using
%lf,%lgor%le(or%lain C99) to read in doubles.