Блог пользователя HitmanBBa

Автор HitmanBBa, история, 9 лет назад, По-английски

Hi everyone.

I hope you're having a good day.

As you see in the picture when I read double using scanf "%lf" specifier it's ok, but when I'm trying to print double using printf "%lf" specifier, I got zero as result, but when I use "%f" floating-point specifier give me the right result, can any one help me with this problem and tell me why?

My IDE: Code::Blocks 13.12

My compiler: GNU GCC Compiler.

Thanks in advance :D

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Can I know why downvotes !!!

If you don't know the answer just ignore it.

»
9 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

Read this page link

Because C will promote floats to doubles for functions that take variable arguments. Pointers aren't promoted to anything, so you should be using %lf, %lg, %le or %la (C99) to read in doubles.