Professional Documents
Culture Documents
c++Differencebetweenformatspecifiers%iand%dinprintfStackOverflow
signup
StackOverflowisacommunityof4.7
millionprogrammers,justlikeyou,
helpingeachother.
login
tour
help
JointheStackOverflowcommunityto:
Jointhemitonlytakesaminute:
Askprogramming
questions
Signup
Answerandhelp
yourpeers
Getrecognizedforyour
expertise
Differencebetweenformatspecifiers%iand%dinprintf
Whatisthedifferencebetween
printf ?
%d
and
%i
whenusedasformatspecifiersin
askedDec12'09at13:49
jason
154k
Ayoub
20
288
431
1,586
28
42
4Answers
033
wouldbe27with
%i
but33with
%d
.
editedApr17at19:52
answeredDec12'09at13:58
taskinoor
29.7k
Dipstick
68
104
6,310
18
20
1 Expectinganintwithpossiblezeropaddinginsscanfseemstometobethemostreasonabledefault
behavior.Ifyou'renotexpectingOctal,thatcouldcausesubtlebugs.Sothissuggeststhat%disagood
specifiertousewhenyouhavetochooseonearbitrarily,unlessyouexplicitlywanttoreadoctaland/or
hex.EliotSep6'13at22:28
answeredDec12'09at13:53
jason
154k
20
288
431
Thereisn'tanyinthosewordsthetwoaresynonyms.
editedMar14'14at8:21
answeredDec12'09at13:52
hqt
9,745
anon
30
92
172
12 @hqt:whyshouldhe?Thisansweriscorrect.Idon'tgetyoupeople(downvoters),thequestionisabout
printf ,not scanf ,thereforetheseanswersarecorrect.Whydownvotethem? ybungalobill Jul11'12
at6:35
http://stackoverflow.com/questions/1893490/differencebetweenformatspecifiersianddinprintf
1/2
5/19/2016
c++Differencebetweenformatspecifiers%iand%dinprintfStackOverflow
appear;ifthevaluebeingconvertedcanberepresentedinfewer
digits,itisexpandedwithleadingzeros.Thedefaultprecisionis
1.Theresultofconvertingazerovaluewithaprecisionofzerois
nocharacters.
editedAug29'14at2:50
answeredAug28'14at20:07
ShafikYaghmour
97.3k
19
217
310
protectedbyRichardJ.RossIIIJun20'12at11:58
Thankyouforyourinterestinthisquestion.Becauseithasattractedlowqualityorspamanswersthathadtoberemoved,postingananswernowrequires10reputation
onthissite.
Wouldyouliketoansweroneoftheseunansweredquestions instead?
http://stackoverflow.com/questions/1893490/differencebetweenformatspecifiersianddinprintf
2/2