+1 vote
in Programming Languages by (74.2k points)
What is the basic difference between "%f" and "%lf" format specifiers?

1 Answer

+2 votes
by (8.9k points)
selected by
 
Best answer

The format specifier "%f" is used for float variables, while "%lf" is used for double variables. However, when using scanf(), there is no need to specify "%lf" because it assumes the input to be of type double by default. It is only necessary to use "%lf" with printf() when printing a double variable.

Here is an example:

#include <stdio.h>

int main() {

    float float_pi = 3.14;

    double double_pi = 3.14159265358979323846;

    printf("Float PI value: %f\n", float_pi);

    printf("Double PI alue: %lf\n", double_pi);  

    return 0;

}


...