%i or %d to print integer in C using printf()?

后端 未结 6 981
春和景丽
春和景丽 2020-12-08 02:08

I am just learning C and I have a little knowledge of Objective-C due to dabbling in iOS development, however, in Objective-C I was using NSLog(@\"%i\", x); to

6条回答
  •  隐瞒了意图╮
    2020-12-08 02:49

    They are completely equivalent when used with printf(). Personally, I prefer %d, it's used more often (should I say "it's the idiomatic conversion specifier for int"?).

    (One difference between %i and %d is that when used with scanf(), then %d always expects a decimal integer, whereas %i recognizes the 0 and 0x prefixes as octal and hexadecimal, but no sane programmer uses scanf() anyway so this should not be a concern.)

提交回复
热议问题