What is the difference between %d and %f in c programming? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the difference between %d and %f in c programming?

22nd Apr 2019, 5:44 PM
Adhan Moge Salah
Adhan Moge Salah - avatar
4 Answers
+ 12
In addition to Edwin's reply, if you use %d to print 5.26, you'll get an unexpected value. https://stackoverflow.com/questions/7480097/what-happens-to-a-float-variable-when-d-is-used-in-a-printf
23rd Apr 2019, 4:10 PM
silentlearner
silentlearner - avatar
+ 7
To print a integer value we use %d like 5 For printing float value we use %f like 5.26
22nd Apr 2019, 5:57 PM
Edwin
Edwin - avatar
+ 6
%d and %f are format specifiers. %d is used for integer(-3,-100,3,100,etc). And %f is used for float(10.6,-39.0,etc).
25th Apr 2019, 4:26 AM
Yamin Mansuri
Yamin Mansuri - avatar
+ 5
%i can also be used for integers.
24th Apr 2019, 2:26 AM
Sonic
Sonic - avatar