c - printf output for cross format specifier -


the below program printing 123828749, 0.000000 expected 123828749, 123828749.0. getting 0.000000 ?

    #include <stdio.h>      void main()      {          double x = 123828749.66;          int y = x;          printf("%d\n", y);          printf("%lf\n", y);      } 

thanks

in second call printf passing int, format string %lf expects floating point value passed. invokes undefined behaviour.

if want treat y floating point value when pass printf, you'll need explicit conversion:

printf("%lf\n", (double)y); 

Comments