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

后端 未结 6 990
春和景丽
春和景丽 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:57

    both %d and %i can be used to print an integer

    %d stands for "decimal", and %i for "integer." You can use %x to print in hexadecimal, and %o to print in octal.

    You can use %i as a synonym for %d, if you prefer to indicate "integer" instead of "decimal."

    On input, using scanf(), you can use use both %i and %d as well. %i means parse it as an integer in any base (octal, hexadecimal, or decimal, as indicated by a 0 or 0x prefix), while %d means parse it as a decimal integer.

    check here for more explanation

    why does %d stand for Integer?

提交回复
热议问题