2

Possible Duplicate:
Difference between format specifiers %i and %d in printf

This question is motivated by the fact I use to see this preference in all the C code I've read.

Community
  • 1
  • 1
EPadronU
  • 49
  • 1
  • 3
  • 1
    @Aravindhanarvi I guess they want some quick reputation? They need to add reputation to finding of duplicates. This question is clearly a dup but no one voted to close. – Hogan Jul 07 '12 at 17:40

3 Answers3

3
%d and %i

mean same in printf i.e. int;signed decimal notation but in scanf

%d is for decimal integer,int * and %i is for integer;int * the integer may be in octal(leading 0) or hexadecimal(leading 0x).

akash
  • 1,801
  • 7
  • 24
  • 42
1

As far as I understand, %d implies base-10 (d is for DECImal), and i is base-flexible (you can use modifiers to indicate octal or hex). So, you should use d if you don't want to think about it, and you always want base-10

Chris Trahey
  • 18,202
  • 1
  • 42
  • 55
0

i and d conversion specifiers are equivalent for fprintf but they are different for fscanf.

Both i and d are present in all C standards (C89, C90, C11).

d is more common than i so I prefer to use d for fprintf.

ouah
  • 142,963
  • 15
  • 272
  • 331