Why are types always a certain size no matter its value?

后端 未结 19 1880
谎友^
谎友^ 2021-01-30 15:22

Implementations might differ between the actual sizes of types, but on most, types like unsigned int and float are always 4 bytes. But why does a type always occupy a certai

19条回答
  •  臣服心动
    2021-01-30 16:04

    Because types fundamentally represent storage, and they are defined in terms of maximum value they can hold, not the current value.

    The very simple analogy would be a house - a house has a fixed size, regardless of how many people live in it, and there is also a building code which stipulates the maximum number of people who can live in a house of a certain size.

    However, even if a single person is living in a house which can accommodate 10, the size of the house is not going to be affected by the current number of occupants.

提交回复
热议问题