0

What is mean by %1d in C language? Can we use only %d instead of %1d?

21st Feb 2020, 9:11 AM
Tarun Gehlot
2 Réponses
+ 3
%d and %1d is same.. There is no meaning to use like %1d... In between %d, the number specifies the number of digits to be reserved in output console, even when the number of digits in number is Less.. For ex: 1 to 9 digits requires only 1width of space, 10 to 99 requires 2, if you give 1 to 99 equal space in output, then %2d will do that for you... Check these by running %d, %2d %3d for same numbers.. If you don't see difference then try like %02d %03d... 0 will be filled in place of space...
21st Feb 2020, 9:52 AM
Jayakrishna 🇮🇳
0
(Because this was literally the first google result, I have seen enough evidence to the contrary, and I am worried about others taking the above answer at face value, I want to offer my findings) %d vs %1d - that the number one, NOT the letter L %1d will read a single digit %d will read the whole number (until it hits whitespace) https://stackoverflow.com/questions/40380157/what-difference-does-it-make-to-use-1d-instead-of-d-only-in-scanf-statemen To help avoid confusion: %d vs %ld - that's the letter L, NOT the number one %ld will read an 8-bit type into a 4-bit type. IBM specifically recommends only using %ld for long data types, and %d otherwise (bottom of page): https://www.ibm.com/docs/en/ibm-mq/7.5?topic=platforms-standard-data-types
26th Oct 2022, 3:33 PM
Graeme