0

doubt

if it is necessary to give input that should match format specifier in scanf then how scanf("%d",&a) accepts float input

22nd Jul 2020, 6:48 PM
S.Brindha
S.Brindha  - avatar
2 odpowiedzi
+ 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....
22nd Jul 2020, 8:48 PM
Jayakrishna 🇮🇳
+ 1
%d doesn’t accepts float input, it just take the integer value of the given float, as like, 10 from 10.67.
25th Jul 2020, 7:30 AM
Tawhidul Islam Fahim
Tawhidul Islam Fahim - avatar