To print out a and b given below, which printf() statement would you use?
float a = 3.14;
double b = 3.14;
Answer: A
Correct answer: printf("%f%f",a,b);
Both are printed with %f. In a call to a variadic function such as printf, the default argument promotions apply, and a float argument is promoted to double before it is passed - so printf receives two doubles and %f is correct for each.
There is therefore no %f for float and separate specifier for double; %f serves both. %Lf is for long double, and using it here would misread the argument and produce nonsense.
Please log in or register to report this question.