IT이야기

포맷된 IO 함수(*printf / *scanf)에서 변환 지정자 %i와 %d의 차이점

cyworld 2022. 5. 9. 22:02
반응형

포맷된 IO 함수(*printf / *scanf)에서 변환 지정자 %i와 %d의 차이점

와의 차이점은 무엇인가?%d그리고%i형식 지정자로 사용되는 경우printf그리고scanf?

예를 들어, 다음과 같은 경우 출력에 사용할 때 동일하다.printf.

단, 이러한 것들은 예를 들어 다음과 같은 입력 지정자로 사용될 때 다르다.scanf어디에%d서명된 소수점 숫자로 정수를 스캔하지만%i기본값은 소수지만 16진수 허용(다음이 앞에 있는 경우)0x) 및 8진수(다음이 앞에 있는 경우)0).

그렇게033와 함께 27일 것이다.%i그러나 33 와 함께.%d.

이것들은 에 대해 동일하다.printf에 있어서 다른.scanf.을 위해printf둘 다, 둘 다%d그리고%i부호 십진 정수를 지정하다을 위해scanf,%d그리고%i또한 서명된 정수를 의미하지만%i다음과 같은 경우 입력을 16진수 숫자로 삽입한다.0x그리고 8진법이 선행될 경우0그리고 다른 방법으로 입력을 십진법으로 해석한다.

두 사람 사이에는 아무런 차이가 없다.%i그리고%d에 대한 지정자를 지정하다printfC99 표준 초안을 보면 알 수 있다.7.19.6.1 fprintf 기능도 포함.printf형식 지정자에 관하여, 제8항에 다음과 같이 명시되어 있다.

변환 지정자와 그 의미는 다음과 같다.

다음 글머리 기호를 포함한다.

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차이가 있다.%d10번 베이스로 하다%i자동 감지.우리는 섹션으로 가면 이것을 볼 수 있다.7.19.6.2 Fscanf 기능:scanf형식 지정자에 관하여, 12항에서 다음과 같이 명시한다.

변환 지정자와 그 의미는 다음과 같다.

그리고 다음을 포함한다.

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- 이 둘은 동의어다.

참조URL: https://stackoverflow.com/questions/1893490/what-is-the-difference-between-conversion-specifiers-i-and-d-in-formatted-io-f

반응형