Does sizeof(pointer) depend on the object type?

This question already has an answer here:

  • The Definitive C++ Book Guide and List 1 answer
  • Is the sizeof(some pointer) always equal to four? 16 answers

  • Please explain why sizeof(B*) return 4?

    It returns 4 because size of a pointer variable is 4 in your system.

    What exactly pointer to object represents in memory?

    Objects reside in memory, and pointer to an object contains the starting memory address of that object. For example, if your B object has size 100 Byte, and it is placed in 1024-1123(100 Bytes) memory location, then a pointer to that object will hold the value `024 (starting address).

    Is pointer to sizeof depends on the object type?

    I guess you meant does pointer size depends on object type?. No, since pointers contain an address, it's size depends on address space of your system, not type of object it points to.


    A pointer to an object represents the address of the object in memory. If in your case it is 4 bytes, it means that you have a 32 bit address space (either the OS, or your program is built in 32bits). To maintain the address of an object you don't really need any knowledge of the object, so a pointer to an incomplete type is fine.

    Note that none of this applies to pointers to members, which are a completely different beast.

    链接地址: http://www.djcxy.com/p/6870.html

    上一篇: 了解C ++

    下一篇: sizeof(指针)是否依赖于对象类型?