Why does sizeof(int) vary across different operating systems?

后端 未结 4 1721
-上瘾入骨i
-上瘾入骨i 2020-12-02 00:55

I wounder why size of int depends on which OS one is using ,in C & C++. It\'s ok if size of pointer varies, but why size of integer. If 16 bit OS sizeof(int) = 2 byte, f

4条回答
  •  暖寄归人
    2020-12-02 01:28

    A byte is the smallest unit of memory which your target system can handle and uniquely address. As such, the size of a byte is platform and compiler-dependant, but in most settings is 8 bits.

    So, assuming a byte is 8 bits, this would mean that 64 bits equals 8 bytes, 32 bits equals 4 bytes and 16 bits equals 2 bytes.

    On a fuzzy level, an "X bit system" is a system where basic values (registers, ints, etc.) are X bits by default. Thus, how many bits your system natively uses immediately affects how many bytes are needed to hold those values.

提交回复
热议问题