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

后端 未结 6 991
春和景丽
春和景丽 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 03:06

    d and i conversion specifiers behave the same with fprintf but behave differently for fscanf.

    As some other wrote in their answer, the idiomatic way to print an int is using d conversion specifier.

    Regarding i specifier and fprintf, C99 Rationale says that:

    The %i conversion specifier was added in C89 for programmer convenience to provide symmetry with fscanf’s %i conversion specifier, even though it has exactly the same meaning as the %d conversion specifier when used with fprintf.

提交回复
热议问题