How to print double value in c

We can print the double value using both %f and %lf format specifier because printf treats both float and double are same.

So, we can use both %f and %lf to print a double value.




Let's print a double d = 123.32445 using both %f and %lf

#include<stdio.h>

int main()
{
    double d = 123.32445;

    //using %f format specifier
    printf("Value of d = %f\n",d);

    //using %lf format specifier
    printf("Value of d = %lf\n",d);

    return 0;
}

Output

Value of d = 123.324450

Value of d = 123.324450


Topics You Might Like