what are default integer values?

后端 未结 3 834
情话喂你
情话喂你 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: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

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题