-3

I am a beginner, just learning C; I am trying to print a 'double long' variable. When I try to run the program, It produces incorrect output! Here is the code:

#include<stdio.h>

int main()
{
    double long x=10;
    printf("%.Lf",x);
    return 0;
}
/*
Output:
-0
Output in online compiler: 
10
*/

I use vs code with gcc. When I try to run the program, it displays wrong value. I tried using an online compiler, It works fine. Here is the online compiler I used: https://rextester.com/l/c_online_compiler_gcc

Thanks.

edit: I tried using %Lf instead of %.Lf, but still the output is -0.000000

XArchenon
  • 3
  • 4

1 Answers1

0

There's a similar problem with MinGW under Windows.

If you run the code with the extension .cpp, it'll show you the correct output.

However, to get the correct output in c , you can use __mingw_printf instead of printf while printing long double values.

Sample code:

#include<stdio.h>

int main()
{
    long double x=10;
    __mingw_printf("%Lf",x);
    return 0;
}

Output:

10.000000

To know more, please check out the following resources:

Md. Faisal Habib
  • 1,014
  • 1
  • 6
  • 14