size of int variable

前端 未结 6 1062
我在风中等你
我在风中等你 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:56

    The size of integer is basically depends upon the architecture of your system. Generally if you have a 16-bit machine then your compiler will must support a int of size 2 byte. If your system is of 32 bit,then the compiler must support for 4 byte for integer.

    In more details,

    • The concept of data bus comes into picture yes,16-bit ,32-bit means nothing but the size of data bus in your system.
    • The data bus size is required for to determine the size of an integer because,The purpose of data bus is to provide data to the processor.The max it can provide to the processor at a single fetch is important and this max size is preferred by the compiler to give a data at time.
    • Basing upon this data bus size of your system the compiler is designed to provide max size of the data bus as the size of integer.
    x06->16-bit->DOS->turbo c->size of int->2 byte
    x306->32-bit>windows/Linux->GCC->size of int->4 byte
    

提交回复
热议问题