what are default integer values?

后端 未结 3 831
情话喂你
情话喂你 2021-01-14 10:43

I read somewhere that default floating point values like 1.2 are double not float.
So what are default integer values like 6

相关标签:
3条回答
  • 2021-01-14 11:12

    Just if someone is interested:

    C11 §6.4.4.1/5:

    The type of an integer constant is the first of the corresponding list in which its value can be represented.

    ---------------------------------------------------------------------------
    Suffix        Decimal Constant              Octal/Hexadecimal Constant
    ---------------------------------------------------------------------------
    none          int                           int
                  long int                      unsigned int
                  long long int                 unsigned long int
                                                long long int
                                                unsigned long long int
    ---------------------------------------------------------------------------
    u or U        unsigned int                  unsigned int
                  unsigned long int             unsigned long int
                  unsigned long long int        unsigned long long int
    ---------------------------------------------------------------------------
    l or L        long int                      long int
                  long long int                 unsigned long int
                                                long long int
                                                unsigned long long int
    ---------------------------------------------------------------------------
    Both u or U   unsigned long int             unsigned long int
    and l or L    unsigned long long int        unsigned long long int
    ---------------------------------------------------------------------------
    ll or LL      long long int                 long long int
                                                unsigend long long int
    ---------------------------------------------------------------------------
    Both u or U   unsigned long long int        unsigned long long int
    and ll or LL
    ---------------------------------------------------------------------------
    

    As for the prefix §6.4.4.1/3:

    A decimal constant begins with a nonzero digit and consists of a sequence of decimal digits. An octal constant consists of the prefix 0 optionally followed by a sequence of the digits 0 through 7 only. A hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of the decimal digits and the letters a (or A) through f (or F) with values 10 through 15 respectively.

    0 讨论(0)
  • 2021-01-14 11:14

    There are three types of integer literals(or integer constants in the standards terminology): decimal, octal or hex and the rule are slightly different for your specific example 6 would be int but in general for decimal constants without a suffix(u, U, l, L, ll, LL) it will be based on which type can represent the value which is covered in the draft C99 standard section 6.4.4.1 Integer constants paragraph 5 which says:

    The type of an integer literal is the first of the corresponding list in which its value can be represented.

    so for a decimal literal without a suffix the types would be the first of:

    • int
    • long int
    • long long int

    and for octal and hex the types would be the first of:

    • int
    • unsigned int
    • long int
    • unsigned long int
    • long long int
    • unsigned long long int
    0 讨论(0)
  • 2021-01-14 11:19

    The type of integer literals given in base 10 is the first type in the following list in which their value can fit:

    • int
    • long int
    • long long int

    For octal and hexadecimal literals, unsigned types will be considered as well, in the following order:

    • int
    • unsigned int
    • long int
    • unsigned long int
    • long long int
    • unsigned long long int

    You can specify a u suffix to force unsigned types, an l suffix to force long or long long, or an ll suffix to force long long.

    Reference: C99, 6.4.4.1p5

    0 讨论(0)
提交回复
热议问题