St.Antario St.Antario - 1 year ago 98
C++ Question

Does sizeof(pointer) depend on the object type?

I'm trying to understand what a pointer to an object means. I'm wondering if

is an incomplete type, why is a pointer to
a complete type. Consider the following program:

#include <stdio.h>

class B; //B is incomplete type here

int main()

Please explain why does
return 4? What exactly does a pointer to an object represent in memory?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download