-2

So, my question is, when I try to use %d as a format specifier and print 'a', which is a floating value, I get the answer as 0. I want to know why that is so.

#include<stdio.h>
#include<conio.h>

void main()
{
    float a = 3.5;
    clrscr();
    printf("The value of a is:%d",a);
    getch();
}
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Aarushi Aiyyar
  • 369
  • 1
  • 5
  • 11
  • `void main()` is not standard C, and mismatching printf conversion specifiers to argument types means your program has undefined behavior. Anything can happen. Printing 0 is the least problematic thing that could happen. – StoryTeller - Unslander Monica Mar 12 '17 at 08:33

1 Answers1

0

The %d specifier only takes integers. To format floating point numbers use %f.

See the printf manpage on how to choose which format specifier you should use for which input.

Daniel
  • 458
  • 5
  • 16