1

enter image description hereWhy in C, when I print a double type variable with %lf it shows 0.000000…but if I use just %f it shows the desire result? Moreover, when we take an input we use %lf for double type variable. Why i am getting 0.0000 instead of 3.0000 ?

1 Answers1

2
for printf %f and %lf can be used interchangeably for floats and double.
for scanf %f  formats float
for scanf %lf formats double

Reason is that scanf take pointer(address of variable) as the input in both cases. Whereas in case of printf which takes actual variables (float or double) as the input parameters which are convertible to each other(type casting)

hrishi
  • 443
  • 2
  • 12