フォーマットIO機能(* printfの/ *のscanf)に変換指定子%Iおよび%dの違いは何ですか

StackOverflow https://stackoverflow.com/questions/1893490

質問

%dに書式指定子として使用%iprintfの違いは何ですか?

役に立ちましたか?

解決

これらは、同じ出力のために使用される場合、例えば、ありますprintf付きます。

入力指定子例えばとして使用される場合、

しかし、これらは異なりますscanfと、%dは、符号付き10進数として整数をスキャンが、%iデフォルト値は小数点することも進(0xが先行する場合)及び(0が先行する場合)オクタルを可能にする。

ここで

だから、033%iと27が、%dと33になります。

他のヒント

これらはprintfため同一であるがscanf異なります。 printfため、%d%i両方は、符号付き10進数の整数を指定します。 scanf%d%iにも符号付き整数を意味するが、%iが先行場合0xとオクタルが先行した場合に16進数で入力を0 intepretsさもなければ小数として入力を解釈します。

%iため%dprintf書式指定子の間に違いはありません。私たちは、/ ドラフトC99標準の:また、書式指定子に対する7.19.6.1をカバーし、それが段落の8 の中で述べているのA>セクションprintf の関数fprintf

  

変換指定子とその意味は次のとおりです:

と、次の箇条書きが含まれます:

d,i     The int argument is converted to signed decimal in the style
        [−]dddd. The precision specifies the minimum number of digits to
        appear; if the value being converted can be represented in fewer
        digits, it is expanded with leading zeros. The default precision is
        1. The result of converting a zero value with a precision of zero is
        no characters.
scanf自動ベースを検出しながら、

差がある%d用一方、%iは、ベース10を想定します。

:私たちは、それが言うの12 の段落で、書式指定子に対する7.19.6.2をカバーするのfscanf関数のセクションscanfに行くことによってこれを見ることができます
  

変換指定子とその意味は次のとおりです:

と次のものが含まれます:

d     Matches an optionally signed decimal integer, whose format is the
      same as expected for the subject sequence of the strtol function with
      the value 10 for the base argument. The corresponding argument shall
      be a pointer to signed integer.

i     Matches an optionally signed integer, whose format is the same as
      expected for the subject sequence of the strtol function with the
      value 0 for the base argument. The corresponding argument shall be a
      pointer to signed integer.

いずれかがprintfではありません - 。2は同義語です。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top