C 정수 상수C Integer Constants

‘정수 상수’는 정수 계열 값을 나타내는 10진수(기수 10), 8진수(기수 8) 또는 16진수(기수 16)입니다.An integer constant is a decimal (base 10), octal (base 8), or hexadecimal (base 16) number that represents an integral value. 정수 상수는 변경할 수 없는 정수 값을 나타낼 때 사용합니다.Use integer constants to represent integer values that cannot be changed.

구문Syntax

integer-constant:integer-constant:
    decimal-constant integer-suffixopt    decimal-constant integer-suffixopt
    octal-constant integer-suffixopt    octal-constant integer-suffixopt
    hexadecimal-constant integer-suffixopt    hexadecimal-constant integer-suffixopt

decimal-constant:decimal-constant:
    nonzero-digit    nonzero-digit
    decimal-constant digit    decimal-constant digit

octal-constant:octal-constant:
    0    0
    octal-constant octal-digit    octal-constant octal-digit

hexadecimal-constant:hexadecimal-constant:
    hexadecimal-prefix hexadecimal-digit    hexadecimal-prefix hexadecimal-digit
    hexadecimal-constant hexadecimal-digit    hexadecimal-constant hexadecimal-digit

hexadecimal-prefix: 다음 중 하나hexadecimal-prefix: one of
    0x 0X    0x 0X

nonzero-digit: 다음 중 하나nonzero-digit: one of
    1 2 3 4 5 6 7 8 9    1 2 3 4 5 6 7 8 9

octal-digit: 다음 중 하나octal-digit: one of
    0 1 2 3 4 5 6 7    0 1 2 3 4 5 6 7

hexadecimal-digit: 다음 중 하나hexadecimal-digit: one of
    0 1 2 3 4 5 6 7 8 9    0 1 2 3 4 5 6 7 8 9
    a b c d e f    a b c d e f
    A B C D E F    A B C D E F

integer-suffix:integer-suffix:
    unsigned-suffix long-suffixopt    unsigned-suffix long-suffixopt
    unsigned-suffix long-long-suffix    unsigned-suffix long-long-suffix
    unsigned-suffix 64-bit-integer-suffix    unsigned-suffix 64-bit-integer-suffix
    long-suffix unsigned-suffixopt    long-suffix unsigned-suffixopt
    long-long-suffix unsigned-suffixopt    long-long-suffix unsigned-suffixopt
    64-bit-integer-suffix    64-bit-integer-suffix

unsigned-suffix: 다음 중 하나unsigned-suffix: one of
    u U    u U

long-suffix: 다음 중 하나long-suffix: one of
    l L    l L

long-long-suffix: 다음 중 하나long-long-suffix: one of
    ll LL    ll LL

64-bit-integer-suffix: 다음 중 하나64-bit-integer-suffix: one of
    i64 I64    i64 I64

i64I64는 Microsoft 고유의 접미사입니다.The i64 and I64 suffixes are Microsoft-specific.

정수 상수는 빼기 기호(-)가 앞에 없는 경우 양수입니다.Integer constants are positive unless they are preceded by a minus sign (-). 빼기 기호는 단항 산술 부정 연산자로 해석됩니다.The minus sign is interpreted as the unary arithmetic negation operator. 이 연산자에 대한 자세한 내용은 단항 산술 연산자를 참조하세요.(See Unary Arithmetic Operators for information about this operator.)

정수 상수가 0x 또는 0X로 시작되는 경우 16진수이고,If an integer constant begins with 0x or 0X, it is hexadecimal. 숫자 0으로 시작되는 경우에는 8진수입니다.If it begins with the digit 0, it is octal. 두 경우에 해당하지 않으면 10진수로 간주됩니다.Otherwise, it is assumed to be decimal.

다음 정수 상수는 같습니다.The following integer constants are equivalent:

28
0x1C   /* = Hexadecimal representation for decimal 28 */
034    /* = Octal representation for decimal 28 */

공백 문자는 정수 상수의 숫자를 구분할 수 없습니다.No white-space characters can separate the digits of an integer constant. 다음 예제에서는 몇 가지 유효한 10진수, 8진수 및 16진수 상수를 보여줍니다.These examples show some valid decimal, octal, and hexadecimal constants.

    /* Decimal Constants */
    int                 dec_int    = 28;
    unsigned            dec_uint   = 4000000024u;
    long                dec_long   = 2000000022l;
    unsigned long       dec_ulong  = 4000000000ul;
    long long           dec_llong  = 9000000000LL;
    unsigned long long  dec_ullong = 900000000001ull;
    __int64             dec_i64    = 9000000000002I64;
    unsigned __int64    dec_ui64   = 90000000000004ui64;

    /* Octal Constants */
    int                 oct_int    = 024;
    unsigned            oct_uint   = 04000000024u;
    long                oct_long   = 02000000022l;
    unsigned long       oct_ulong  = 04000000000UL;
    long long           oct_llong  = 044000000000000ll;
    unsigned long long  oct_ullong = 044400000000000001Ull;
    __int64             oct_i64    = 04444000000000000002i64;
    unsigned __int64    oct_ui64   = 04444000000000000004uI64;

    /* Hexadecimal Constants */
    int                 hex_int    = 0x2a;
    unsigned            hex_uint   = 0XA0000024u;
    long                hex_long   = 0x20000022l;
    unsigned long       hex_ulong  = 0XA0000021uL;
    long long           hex_llong  = 0x8a000000000000ll;
    unsigned long long  hex_ullong = 0x8A40000000000010uLL;
    __int64             hex_i64    = 0x4a44000000000020I64;
    unsigned __int64    hex_ui64   = 0x8a44000000000040Ui64;

참고 항목See also

C 상수C Constants