C Quiz – 106 | Question 3

In a C program, following variables are defined:

filter_none

edit
close

play_arrow

link
brightness_4
code

float      x = 2.17;
double   y = 2.17;
long double z = 2.17;

chevron_right


Which of the following is correct way for printing these variables via printf.
(A) printf(“%f %lf %Lf”,x,y,z);
(B) printf(“%f %f %f”,x,y,z);
(C) printf(“%f %ff %fff”,x,y,z);
(D) printf(“%f %lf %llf”,x,y,z);


Answer: (A)

Explanation: In C language, float, double and long double are called real data types. For “float”, “double” and “long double”, the right format specifiers are %f, %lf and %Lf from the above options. It should be noted that C standard has specified other format specifiers as well for real types which are %g, %e etc.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.