search

Home  >  Q&A  >  body text

c++ - 为什么指针变量 的sizeof()打印出来的都是 4;

PHP中文网PHP中文网2803 days ago1275

reply all(5)I'll reply

  • 阿神

    阿神2017-04-17 14:34:34

    The number of bytes occupied by the pointer is related to the number of processor bits. A 32-bit processor is 4 bytes. Although you may have a 64-bit processor, it depends on whether you are a 64-bit program, so as long as int is 4 bytes, then the pointer is still 4 bytes

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 14:34:34

    The pointer saves an address, not any other data. . . So the size is fixed

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 14:34:34

    The pointer is 4 bytes in 32-bit and 8 bytes in 64-bit.
    4 bytes can represent up to 4G.

    The pointer is like a house number. Whether it is a large villa or a small store, there is no difference in the house number.
    It only represents an address and has nothing to do with the content of the address

    reply
    0
  • 阿神

    阿神2017-04-17 14:34:34

    The pointer points to the address. As a 32-bit machine, the address is 4*8=32 bits, that is, the pointer size under a 32-bit machine is 4;
    If it is a 64-bit machine, then the address It is 8*8=64 bits, that is, the pointer size under the 64-bit machine is 8;

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 14:34:34

    As mentioned above, the pointer is like a house number. No matter how large a house it is pointing to, the house number always has 4 digits.

    reply
    0
  • Cancelreply