0
doubt
if it is necessary to give input that should match format specifier in scanf then how scanf("%d",&a) accepts float input
2 Answers
+ 1
It doesnot accept full.
Actually, When you run code in playground, if specify %d then it ready to accept an integer and reads all valid digits you enter one by one until it find other than a digit.. Because we know all integer are not have equal number of digits like
123456789 is an integer, also
234 is also an integer.
so reading digits stops when it encounter other than digit(0-9)
So test this by giving input like
12345asdfg (only reads 12345)
12.5 (only reads 12)
a1234 (here don't reads any..)
So on encounter of dot in 12.5, it stops reading value into integer.
Hope this helps you....
+ 1
%d doesnât accepts float input, it just take the integer value of the given float, as like, 10 from 10.67.