size of int variable

前端 未结 6 1070
我在风中等你
我在风中等你 2020-11-30 14:34

How the size of int is decided?

Is it true that the size of int will depend on the processor. For 32-bit machine, it will be 32 bits and for 16-bit it\'s 16.

6条回答
  •  生来不讨喜
    2020-11-30 14:55

    It depends on the implementation. The only thing the C standard guarantees is that

    sizeof(char) == 1
    

    and

    sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
    

    and also some representable minimum values for the types, which imply that char is at least 8 bits long, int is at least 16 bit, etc.

    So it must be decided by the implementation (compiler, OS, ...) and be documented.

提交回复
热议问题